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.

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);2. Set the cookie value to empty
setcookie($cookiename, '') setcookie($cookiename, NULL);
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!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.






