From 5ec0fcca21b727106960bde29554028d1c1dc6c1 Mon Sep 17 00:00:00 2001 From: Virgil-Adrian Teaca Date: Tue, 12 Apr 2016 16:38:45 +0200 Subject: [PATCH 1/4] Fix the the behavior of the method 'destroy' into Helpers\Cookie --- system/Helpers/Cookie.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/system/Helpers/Cookie.php b/system/Helpers/Cookie.php index 13601a7c80..16136a9a69 100644 --- a/system/Helpers/Cookie.php +++ b/system/Helpers/Cookie.php @@ -44,11 +44,10 @@ public static function set($key, $value, $expiry = self::FOURYEARS, $path = "/", { $retval = false; - if (! headers_sent()) { - if ($domain === false) { - $domain = $_SERVER['HTTP_HOST']; - } + // Ensure to have a valid domain. + $domain = ($domain !== false) ? $domain : $_SERVER['HTTP_HOST']; + if (! headers_sent()) { if ($expiry === -1) { $expiry = 1893456000; // Lifetime = 2030-01-01 00:00:00 } else if (is_numeric($expiry)) { @@ -94,10 +93,16 @@ public static function display() * @param string $path Optional * @param string $domain Optional */ - public static function destroy($key, $path = "/", $domain = "") + public static function destroy($key, $path = "/", $domain = false) { unset($_COOKIE[$key]); - setcookie($key, '', time() - 3600, $path, $domain); + // Ensure to have a valid domain. + $domain = ($domain !== false) ? $domain : $_SERVER['HTTP_HOST']; + + if (! headers_sent()) { + // To delete the Cookie we set its expiration 100 days into past. + @setcookie($key, '', time() - 100 * 24 * 3600, $path, $domain); + } } } From e608f0f8faa3d4ac47eff2735abe672a2f3e94a7 Mon Sep 17 00:00:00 2001 From: Virgil-Adrian Teaca Date: Tue, 12 Apr 2016 16:41:49 +0200 Subject: [PATCH 2/4] Small changes into Helpers\Cookie --- system/Helpers/Cookie.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system/Helpers/Cookie.php b/system/Helpers/Cookie.php index 16136a9a69..96be0543f2 100644 --- a/system/Helpers/Cookie.php +++ b/system/Helpers/Cookie.php @@ -40,7 +40,7 @@ public static function exists($key) * @param bool $domain * @return bool */ - public static function set($key, $value, $expiry = self::FOURYEARS, $path = "/", $domain = false) + public static function set($key, $value, $expiry = self::FOURYEARS, $path = '/', $domain = false) { $retval = false; @@ -93,7 +93,7 @@ public static function display() * @param string $path Optional * @param string $domain Optional */ - public static function destroy($key, $path = "/", $domain = false) + public static function destroy($key, $path = '/', $domain = false) { unset($_COOKIE[$key]); @@ -101,8 +101,8 @@ public static function destroy($key, $path = "/", $domain = false) $domain = ($domain !== false) ? $domain : $_SERVER['HTTP_HOST']; if (! headers_sent()) { - // To delete the Cookie we set its expiration 100 days into past. - @setcookie($key, '', time() - 100 * 24 * 3600, $path, $domain); + // To delete the Cookie we set its expiration four years into past. + @setcookie($key, '', time() - FOURYEARS, $path, $domain); } } } From a8e03e746780c7dbdf30e8ebdcb9192070addfbb Mon Sep 17 00:00:00 2001 From: Virgil-Adrian Teaca Date: Tue, 12 Apr 2016 16:49:06 +0200 Subject: [PATCH 3/4] Small change into Helpers\Cookie --- system/Helpers/Cookie.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Helpers/Cookie.php b/system/Helpers/Cookie.php index 96be0543f2..df5a3922a5 100644 --- a/system/Helpers/Cookie.php +++ b/system/Helpers/Cookie.php @@ -95,12 +95,12 @@ public static function display() */ public static function destroy($key, $path = '/', $domain = false) { - unset($_COOKIE[$key]); - // Ensure to have a valid domain. $domain = ($domain !== false) ? $domain : $_SERVER['HTTP_HOST']; if (! headers_sent()) { + unset($_COOKIE[$key]); + // To delete the Cookie we set its expiration four years into past. @setcookie($key, '', time() - FOURYEARS, $path, $domain); } From 1bae0e36f7448a684a757a24003f576c4650009d Mon Sep 17 00:00:00 2001 From: Virgil-Adrian Teaca Date: Tue, 12 Apr 2016 17:08:26 +0200 Subject: [PATCH 4/4] Simplify the method 'exists' into Helpers\Cookie --- system/Helpers/Cookie.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/system/Helpers/Cookie.php b/system/Helpers/Cookie.php index df5a3922a5..706ac514fb 100644 --- a/system/Helpers/Cookie.php +++ b/system/Helpers/Cookie.php @@ -23,11 +23,7 @@ class Cookie */ public static function exists($key) { - if (isset($_COOKIE[$key])) { - return true; - } else { - return false; - } + return isset($_COOKIE[$key]); } /**