简体   繁体   中英

PHP Expire cookie

I am new to cookies and looking to make this cookie expire on my logout page

Here is where I set the cookie:

   setcookie("loggood", "YES", $expire, "/", "", 0);  
    setcookie("user", $pid, $expire, "/", "", 0);    

Can anyone help me with how to make a cookie expire so the user can logout?

Thanks

If you want to delete a cookie, then just set $expire time to be in the past:

setcookie("loggood", "", time() - 3600);
setcookie("user", "", time() - 3600);

Notes from PHP documentation :

When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM