mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
031ab93e97
http://svn.silverstripe.com/open/modules/sapphire/branches/govtsecurity ........ r52120 | sminnee | 2008-04-03 21:40:18 +1300 (Thu, 03 Apr 2008) | 1 line Fix operation of Cookie::forceExpiry() during testing. ........ git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@53464 467b73ca-7a2a-4603-9d3b-597d59a354a9
43 lines
1.0 KiB
PHP
Executable File
43 lines
1.0 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* @package sapphire
|
|
* @subpackage misc
|
|
*/
|
|
|
|
/**
|
|
* A set of static methods for manipulating cookies.
|
|
* @package sapphire
|
|
* @subpackage misc
|
|
*/
|
|
class Cookie extends Object {
|
|
/**
|
|
* Set a cookie variable
|
|
* @param name The variable name
|
|
* @param value The variable value. May be an array or object if you wish.
|
|
* @param expiryDays The expiry time, in days. Defaults to 90.
|
|
*/
|
|
static function set($name, $value, $expiryDays = 90) {
|
|
if(!headers_sent($file, $line)) {
|
|
setcookie($name, $value, time()+(86400*$expiryDays), Director::baseURL());
|
|
$_COOKIE[$name] = $value;
|
|
} else {
|
|
// if(Director::isDevMode()) user_error("Cookie '$name' can't be set. The site started outputting was content at line $line in $file", E_USER_WARNING);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get a cookie variable
|
|
*/
|
|
static function get($name) {
|
|
return isset($_COOKIE[$name]) ? $_COOKIE[$name] : null;
|
|
}
|
|
|
|
static function forceExpiry( $name ) {
|
|
if(!headers_sent($file, $line)) {
|
|
setcookie( $name, null, time() - 86400 );
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|