Mac Taylor Mac Taylor - 1 year ago 349
PHP Question

how to delete all cookies of my website in php

I'm wondering if I can delete all my website's cookies when a user click on logout, because I used this as function to delete cookies but it isn't work properly:


Is there a way to delete one domain's cookies in PHP?

Answer Source

PHP setcookie()

Taken from that page, this will unset all of the cookies for your domain:

// 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, '/');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download