Cookie Class
The cookie class allows you to get, set and delete cookies.
The cookie class defines the following public variables that you can access:
Variable |
Static |
Type |
Default |
Description |
$expiration |
Yes |
integer |
0
|
Number of seconds before the cookie expires. This value will be used when $expiration is not specified when you call the set() method. |
$path |
Yes |
string |
'/'
|
Restrict the path that the cookie is available to. This value will be used when $path is not specified when you call the set() method. |
$domain |
Yes |
string |
null
|
Restrict the domain that the cookie is available to. This value will be used when $domain is not specified when you call the set() method. |
$secure |
Yes |
boolean |
false
|
Set to true if you only want to transmit cookies over secure connections. |
$httponly |
Yes |
boolean |
false
|
Allow only transmit of cookies over HTTP, disabling Javascript access. |
get($name, $default = null)
The get method allows you to read a $_COOKIE variable.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$name |
Required |
The key in the $_COOKIE array. |
$default |
null
|
What value should be returned if the array item is not found? |
|
Returns |
mixed |
Example |
$theme = Cookie::get('theme', 'blue');
|
set($name, $value, $expiration = null, $path = null, $domain = null)
The set method allows you to create a cookie.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$name |
Required |
The key in the $_COOKIE array. |
$value |
Required |
The value of the cookie. |
$expiration |
null
|
Number of seconds the cookie should last for. |
$path |
null
|
The path on the server in which the cookie will be available on. |
$domain |
null
|
The domain that the cookie is available to. |
|
Returns |
boolean |
Example |
Cookie::set('theme', 'blue', 60 * 60 * 24);
|
delete($name)
The delete method deletes a parameter from the $_COOKIE array.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$name |
Required |
Remove a cookie item. |
|
Returns |
void |
Example |
Cookie::delete('theme')
|