How to clear browser cookies in php server

coldplay.xixi
Release: 2023-03-07 07:06:01
Original
2440 people have browsed it

How the PHP server clears browser cookies: 1. Set the expiration time of the cookie; 2. Set the cookie value to empty, the code is [setcookie($cookiename, '') setcookie($cookiename, NULL) ;].

How to clear browser cookies in php server

How to clear browser cookies by php server:

1. Setting cookies Expiration time

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

2. Set the cookie value to be empty

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

3. The problem of setcookie taking effect immediately in php

Use the method setcookie to set the cookie, but it will not work after setcookie It will 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 a cookie, and the second step is Assignment.

Related learning recommendations: php programming (video)

The above is the detailed content of How to clear browser cookies in php server. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!