Home  >  Article  >  Backend Development  >  How to delete cookies correctly in php

How to delete cookies correctly in php

王林
王林Original
2020-11-05 11:08:002421browse

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 ","");].

How to delete cookies correctly in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn