diff options
author | Simon Rettberg | 2019-10-31 12:21:35 +0100 |
---|---|---|
committer | Simon Rettberg | 2019-10-31 12:21:35 +0100 |
commit | 8c18415ccb3d32db6e89ea00275425cc69793908 (patch) | |
tree | affbf6750781f2ffdf1409bf150349d3c4bb7204 /inc/util.inc.php | |
parent | [baseconfig] Improved verbose output of plain config (diff) | |
download | slx-admin-8c18415ccb3d32db6e89ea00275425cc69793908.tar.gz slx-admin-8c18415ccb3d32db6e89ea00275425cc69793908.tar.xz slx-admin-8c18415ccb3d32db6e89ea00275425cc69793908.zip |
[inc/Util] Add method to agressively unset a cookie
This tries to work around problems with the cookie path
and trailing slashes.
Diffstat (limited to 'inc/util.inc.php')
-rw-r--r-- | inc/util.inc.php | 20 |
1 files changed, 20 insertions, 0 deletions
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); + } + } + } |