Home > Backend Development > PHP Problem > How to delete cookies correctly in php

How to delete cookies correctly in php

王林
Release: 2023-03-07 10:46:01
Original
2427 people have browsed it

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);
Copy after login

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","");
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template