Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ENHANCEMENT: keep Cookie::forceExpiry() consistent with Cookie::set()…

… for preventing cookies from not being deleted. Fixes #56
  • Loading branch information...
commit 075cb5d7b9a5c994a054815f0bc8a1d9cf6b9813 1 parent 6977484
@wilr wilr authored
Showing with 14 additions and 9 deletions.
  1. +14 −9 control/Cookie.php
View
23 control/Cookie.php
@@ -1,10 +1,15 @@
<?php
/**
* A set of static methods for manipulating cookies.
+ *
* @package sapphire
* @subpackage misc
*/
class Cookie {
+
+ /**
+ * @var boolean
+ */
static $report_errors = true;
/**
@@ -12,15 +17,15 @@ class Cookie {
*
* @param string $name The variable name
* @param string $value The variable value. May be an array or object if you wish.
- * @param int $expiryDays The expiry time, in days. Defaults to 90.
+ * @param int $expiry The expiry time, in days. Defaults to 90.
* @param string $path See http://php.net/set_session
* @param string $domain See http://php.net/set_session
* @param boolean $secure See http://php.net/set_session
* @param boolean $httpOnly See http://php.net/set_session (PHP 5.2+ only)
*/
- static function set($name, $value, $expiryDays = 90, $path = null, $domain = null, $secure = false, $httpOnly = false) {
+ static function set($name, $value, $expiry = 90, $path = null, $domain = null, $secure = false, $httpOnly = false) {
if(!headers_sent($file, $line)) {
- $expiry = $expiryDays > 0 ? time()+(86400*$expiryDays) : 0;
+ $expiry = $expiry > 0 ? time()+(86400*$expiry) : $expiry;
$path = ($path) ? $path : Director::baseURL();
// Versions of PHP prior to 5.2 do not support the $httpOnly value
@@ -30,7 +35,8 @@ static function set($name, $value, $expiryDays = 90, $path = null, $domain = nul
setcookie($name, $value, $expiry, $path, $domain, $secure, $httpOnly);
}
} else {
- if(self::$report_errors) user_error("Cookie '$name' can't be set. The site started outputting was content at line $line in $file", E_USER_WARNING);
+ if(self::$report_errors)
+ suser_error("Cookie '$name' can't be set. The site started outputting was content at line $line in $file", E_USER_WARNING);
}
}
@@ -41,18 +47,17 @@ static function get($name) {
return isset($_COOKIE[$name]) ? $_COOKIE[$name] : null;
}
- static function forceExpiry( $name ) {
+ static function forceExpiry($name, $path = null, $domain = null) {
if(!headers_sent($file, $line)) {
- setcookie( $name, null, time() - 86400 );
+ self::set($name, null, -20, $path, $domain);
}
}
static function set_report_errors($reportErrors) {
self::$report_errors = $reportErrors;
}
+
static function report_errors() {
return self::$report_errors;
}
-}
-
-?>
+}
Please sign in to comment.
Something went wrong with that request. Please try again.