/
Cookie.php
55 lines (50 loc) · 1.44 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
<?php
/*
* Made by Samerton
* https://github.com/NamelessMC/Nameless/
* NamelessMC version 2.0.0-dev
*
* License: MIT
*
* Cookie class
*/
class Cookie {
/**
* Check the specified cookie exists.
*
* @param string $name Name of cookie to check
* @return bool Whether this cookie exists or not.
*/
public static function exists(string $name): bool {
return isset($_COOKIE[$name]);
}
/**
* Return the value of the specified cookie.
*
* @param string $name Name of cookie to return value of
*/
public static function get(string $name) {
return $_COOKIE[$name];
}
/**
* Create a new cookie.
*
* @param string $name Name of cookie to create.
* @param string $value Value to store in cookie.
* @param int $expiry When does the cookie expire?
* @param ?bool $secure Create as secure cookie?
* @param ?bool $httpOnly Create as httpOnly cookie?
* @return bool Whether cookie was set or not
*/
public static function put(string $name, string $value, int $expiry, ?bool $secure = false, ?bool $httpOnly = false): bool {
return setcookie($name, $value, time() + $expiry, '/', null, $secure, $httpOnly);
}
/**
* Delete a cookie.
*
* @param string $name Name of cookie to delete
*/
public static function delete(string $name): bool {
return setcookie($name, '', time() - 1, '/');
}
}