Home > Article > Backend Development > How to delete cookies correctly in php
The correct way to delete cookies in php is to change the expiration date to a point in time in the past, such as [setcookie("username",$username,time() 60*60*2);setcookie("username ","");].
Set cookies:
(Related learning video recommendations: java video tutorial)
setcookie("username",$username,time()+60*60*2);
The time of this cookie is the current time, which is the time when the cookie was first set (time() 60 seconds 60 seconds 2) plus 2 hours. The cookie will be cleared after 2 hours, otherwise, it will be cleared after closing the browser.
Deleting cookies:
When deleting a cookie, you should change the expiration date to a point in time in the past.
setcookie("username","");
Related recommendations: php training
The above is the detailed content of How to delete cookies correctly in php. For more information, please follow other related articles on the PHP Chinese website!