-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cookie.php
64 lines (59 loc) · 1.26 KB
/
Cookie.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* Cookie wrapper
*
* @since 2019-01-09
* @version 1.0
* @author Dwayne Walsh
* @link https://github.com/DwayneWalsh
*
*/
class Cookie
{
/**
* Checks if cookie exists
* @param string $name A cookie name
*
* @return boolean
*/
public static function exists($name)
{
return (isset($_COOKIE[$name]) ? true : false);
}
/**
* Gets a cookie`s value if it exists
* @param string $name A cookie name
*
* @return string
*/
public static function get($name)
{
if(self::exists($name)) {
return $_COOKIE[$name];
}
return '';
}
/**
* Creates a cookie
* @param string $name A cookie name
* @param string $value Value of a cookie
* @param string $expiry Expiry date of a cookie
*
* @return boolean
*/
public static function put($name, $value, $expiry)
{
if(setcookie($name, $value, time() + $expiry, '/')) {
return true;
}
return false;
}
/**
* Deletes a cookie
* @param string $name A cookie name
*/
public static function delete($name)
{
self::put($name, '', time() - 1);
}
}