Delete Cookies

Cookies Deleted!

The demo cookies have been removed.

HTTP Response Headers Sent

Set-Cookie: demo_username=deleted; expires=Wed, 04 Feb 2026 02:04:08 GMT; path=/
Set-Cookie: demo_theme=deleted; expires=Wed, 04 Feb 2026 02:04:08 GMT; path=/
Set-Cookie: demo_created=deleted; expires=Wed, 04 Feb 2026 02:04:08 GMT; path=/
How deletion works:
  1. We set each cookie with an expiration time in the past
  2. Server sends Set-Cookie headers with past expiration
  3. Browser sees the expired date and removes the cookies
  4. Future requests won't include these cookies

The PHP Code That Deleted These

<?php
// To delete a cookie, set it with an expiration in the past
// IMPORTANT: Must use same 'path' as when cookie was set!

setcookie('demo_username', '', [
    'expires' => time() - 3600,  // 1 hour ago
    'path' => '/'                // Same path as when set
]);

setcookie('demo_theme', '', [
    'expires' => time() - 3600,
    'path' => '/'
]);

// Alternative syntax (older PHP style):
// setcookie('demo_username', '', time() - 3600, '/');
?>

Common Deletion Mistakes

Mistake Why It Fails
Wrong path Cookie set with path=/ won't be deleted if you omit path
Wrong domain Cookie for .example.com won't delete if you specify www.example.com
Just unsetting value setcookie('name', '') sets empty value, doesn't delete

Current $_COOKIE Contents

(This shows what the browser sent with this request - deletion takes effect on next request)

(No cookies)

Verify Deletion

Check Cookies Set New Cookies


Back to Cookies Demo | Next: Server Sessions