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

How to delete cookies in php

王林
Release: 2023-03-07 06:10:01
Original
2223 people have browsed it

How to delete cookies in php: Just change the expiration date to a point in time in the past, such as [setcookie("user", "", time()-3600);].

How to delete cookies in php

Method to delete cookies:

When you need to delete cookies, you should change the expiration date to a point in time in the past.

(Video tutorial recommendation: php video tutorial)

Deleted instance:

<?php
// 设置 cookie 过期时间为过去 1 小时
setcookie("user", "", time()-3600);
?>
Copy after login

Create cookie

setcookie() function Used to set cookies.

Note: The setcookie() function must be located before the tag.

Example:

In the following example, we will create a cookie named "user" and assign it the value "runoob". We also specify that this cookie expires after one hour:

<?php
    setcookie("user", "runoob", time()+3600);
?>
<html>
.....
Copy after login

Related recommendations: php training

The above is the detailed content of How to delete cookies 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