Purging Website Cookies in PHP Upon User Logout
To effectively remove all cookies associated with your website when a user logs out, the setcookie function alone may not suffice as it only unsets a specific cookie. A more comprehensive solution is required to tackle this task.
PHP setcookie()
The setcookie function enables the manipulation of cookies. Referencing the official PHP documentation, this code snippet erases all cookies for your domain:
<code class="php">// unset cookies if (isset($_SERVER['HTTP_COOKIE'])) { $cookies = explode(';', $_SERVER['HTTP_COOKIE']); foreach($cookies as $cookie) { $parts = explode('=', $cookie); $name = trim($parts[0]); setcookie($name, '', time()-1000); setcookie($name, '', time()-1000, '/'); } }</code>
The above is the detailed content of How to Effectively Purge All Website Cookies in PHP Upon User Logout?. For more information, please follow other related articles on the PHP Chinese website!