Home  >  Article  >  Backend Development  >  How to clear cookies in browser in php

How to clear cookies in browser in php

王林
王林Original
2020-08-19 13:41:412442browse

php method to clear cookies in the browser: You can use the setcookie() function to set the cookie expiration time to achieve the purpose of clearing cookies. The setcookie() function is used to send an HTTP cookie to the client.

How to clear cookies in browser in php

# The setcookie() function sends an HTTP cookie to the client.

(Recommended tutorial: php graphic tutorial)

The cookie must be assigned before any other output is sent to the client. If successful, the function returns TRUE. Returns FALSE on failure.

Syntax:

setcookie(name,value,expire,path,domain,secure)

Parameters:

  • ##name Required. Specifies the name of the cookie.

  • #value Required. Specifies the cookie value.

  • #expire Optional. Specifies the cookie expiration time.

  • path Optional. Specifies the server path for cookies.

  • domain Optional. Specifies the domain name for the cookie.

  • secure Optional. Specifies whether cookies need to be transmitted over a secure HTTPS connection. Set to TRUE if the cookie needs to be transmitted over a secure HTTPS connection. Default is FALSE.

(Learning video recommendation:

php video tutorial)

Implementation code:

//将过期时间设为一小时前
setcookie("TestCookie", "", time() - 3600);

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