Skip to content

Commit

Permalink
Merge pull request #728 from LuckyCyborg/master
Browse files Browse the repository at this point in the history
Fix the the behavior of the method 'destroy' into Helpers\Cookie
  • Loading branch information
daveismynamecom committed Apr 12, 2016
2 parents f9982b0 + 1bae0e3 commit 0e29f87
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions system/Helpers/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ class Cookie
*/
public static function exists($key)
{
if (isset($_COOKIE[$key])) {
return true;
} else {
return false;
}
return isset($_COOKIE[$key]);
}

/**
Expand All @@ -40,15 +36,14 @@ 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;

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)) {
Expand Down Expand Up @@ -94,10 +89,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]);
// Ensure to have a valid domain.
$domain = ($domain !== false) ? $domain : $_SERVER['HTTP_HOST'];

setcookie($key, '', time() - 3600, $path, $domain);
if (! headers_sent()) {
unset($_COOKIE[$key]);

// To delete the Cookie we set its expiration four years into past.
@setcookie($key, '', time() - FOURYEARS, $path, $domain);
}
}
}

0 comments on commit 0e29f87

Please sign in to comment.