silverstripe-framework/core/Cookie.php
Hayden Smith 4a5d9b03f8 Moved Sapphire module to open source path
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@39001 467b73ca-7a2a-4603-9d3b-597d59a354a9
2007-07-19 10:40:28 +00:00

31 lines
848 B
PHP
Executable File

<?php
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 ) {
setcookie( $name, null, time() - 86400 );
}
}
?>