Add Cookie::remove()

This commit is contained in:
Giuseppe Criscione 2021-07-22 13:21:20 +02:00
parent 01e1da4ae3
commit f5d224c8ec
2 changed files with 11 additions and 1 deletions

View File

@ -32,6 +32,16 @@ class Cookie
Header::send('Set-Cookie', Header::make($data), $replace);
}
/**
* Remove a cookie
*
* @param bool $replace Whether to replace existing Set-Cookie header
*/
public static function remove(string $name, array $options = [], bool $replace = false): void
{
static::send($name, '', ['expires' => time() - 3600] + $options, $replace);
}
/**
* Return an array containing the default cookie directives
*/

View File

@ -35,7 +35,7 @@ class Session
Cookie::send(self::SESSION_NAME, session_id(), $options, true);
} elseif (HTTPRequest::cookies()->get(self::SESSION_NAME) !== session_id()) {
// Remove cookie if session id is not valid
Cookie::send(self::SESSION_NAME, '', ['expires' => time() - 3600] + $options, true);
Cookie::remove(self::SESSION_NAME, $options, true);
}
}
}