Delete a Cookie in PHP

Delete a cookie using the same path

Expire the cookie in the past and use the same path/domain scope used when it was created.

<?php
setcookie('Plus2netCookie', '', [
    'expires' => time() - 3600,
    'path' => '/',
    'secure' => true,
    'httponly' => true,
    'samesite' => 'Lax',
]);
?>
Cookie note: Secure cookies require HTTPS. Choose SameSite and HttpOnly settings according to how the cookie is actually used.

Current example first; the detailed tutorial examples below are retained for additional learning and comparison.

Cookie is removed. You can check this by going to Reading Cookies page to check.
setcookie ("Plus2netCookie", "", time() - 3600);
Here time() gives us the time elapsed in seconds between current time and Unix Epoch (January 1 1970 00:00:00 GMT). From this value we are subtracting 3600 seconds to give a past time as expire time for the cookie.



Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
©2000-2026   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer