php browser delete cookies

藏色散人
Release: 2023-03-09 22:58:01
Original
2573 people have browsed it

How to delete cookies in PHP browser: 1. Set the cookie expiration time; 2. Set the cookie value to empty; 3. Use the setcookie method to set the cookie.

php browser delete cookies

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

php server deletes browser cookies

1. Set the cookie expiration time

//将过期时间设为一小时前
setcookie("TestCookie", "", time() - 3600);
setcookie("TestCookie", "", time() - 3600, "/~rasmus/", ".utoronto.ca", 1);
Copy after login

2. Set the cookie value to empty

setcookie($cookiename, '')
setcookie($cookiename, NULL);
Copy after login

3. Setcookie in PHP will take effect immediately Problem

Use method setcookie to set cookie, but setcookie will not take effect immediately. If you get $_cookie immediately, you will not get the value. Refresh the page again to get the value.

Look at the cookie item in the network in the chrome developer tools, you will see that there is no value in the request cookie, but there is a value in the response cookie (I don’t know the difference between them yet)

If you want it to take effect immediately, you can setcookie(cookiename,value) and then $_cookie[cookiename]=value

The first step is to create the cookie, and the second step is to assign the value.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of php browser delete cookies. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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