From: Florent Bruneau Date: Sun, 21 Dec 2008 18:05:13 +0000 (+0100) Subject: Cookie management using Cookie:: class. X-Git-Tag: core/1.0.1~53 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=f09d3319de8a65f5eb11ce0e73a3dc08a72c4091;p=platal.git Cookie management using Cookie:: class. * Cookie::set() to set a cookie for a given number of days. * Cookie::kill() to kill a cookie. Both methods change the value of the cookie both remotely (cookie stored by the browser) and locally ($_COOKIE and Cookie::). Signed-off-by: Florent Bruneau --- diff --git a/classes/env.php b/classes/env.php index 61cc6cf..5b6a2b9 100644 --- a/classes/env.php +++ b/classes/env.php @@ -197,19 +197,33 @@ class Cookie { public static function _get($key, $default) { + global $globals; + $key = $globals->cookie_ns . $key; return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default; } public static function has($key) { + global $globals; + $key = $globals->cookie_ns . $key; return isset($_COOKIE[$key]); } public static function kill($key) { + global $globals; + $key = $globals->cookie_ns . $key; + setcookie($key, '', time() - 3600, $globals->cookie_path); unset($_COOKIE[$key]); } + public static function set($key, $value, $days) { + global $globals; + $key = $globals->cookie_ns . $key; + setcookie($key, $value, time() + 86400 * $days, $globals->cookie_path); + $_COOKIE[$key] = $value; + } + public static function v($key, $default = null) { return Cookie::_get($key, $default); diff --git a/classes/plglobals.php b/classes/plglobals.php index ab50d9f..686afd5 100644 --- a/classes/plglobals.php +++ b/classes/plglobals.php @@ -87,6 +87,11 @@ class PlGlobals public $locale; public $timezone; + /** Cookie configuration. + */ + public $cookie_ns = 'ORG'; + public $cookie_path = '/'; + /** You must give a list of file to load. * The filenames given are relatives to the config path of your plat/al installation. */