Home  >  Article  >  Backend Development  >  How to delete cookies in php

How to delete cookies in php

王林
王林Original
2020-11-03 11:24:542137browse

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);
?>

Create cookie

setcookie() function Used to set cookies.

Note: The setcookie() function must be located before the 100db36a723c770d327fc0aef2ce13b1 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>
.....

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!

Statement:
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