From 8c18415ccb3d32db6e89ea00275425cc69793908 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 31 Oct 2019 12:21:35 +0100 Subject: [inc/Util] Add method to agressively unset a cookie This tries to work around problems with the cookie path and trailing slashes. --- inc/util.inc.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'inc/util.inc.php') diff --git a/inc/util.inc.php b/inc/util.inc.php index c33bbc83..9c9d4e58 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -534,4 +534,24 @@ SADFACE; return implode(' ', $parts) . ' ' . gmdate($showSecs ? 'H:i:s' : 'H:i', $seconds); } + /** + * Properly clear a cookie from the user's browser. + * This recursively wipes it from the current script's path. There + * was a weird problem where firefox would keep sending a cookie with + * path /slx-admin/ but trying to delete it from /slx-admin, which php's + * setcookie automatically sends by default, did not clear it. + * @param string $name cookie name + */ + public static function clearCookie($name) + { + $parts = explode('/', $_SERVER['SCRIPT_NAME']); + $path = ''; + foreach ($parts as $part) { + $path .= $part; + setcookie($name, '', 0, $path); + $path .= '/'; + setcookie($name, '', 0, $path); + } + } + } -- cgit v1.2.3-55-g7522