How does PHP handle the problem of setcookie invalidation


1. The browser opens the cookie.

2. Delete any HTTP header output before setcookie().

3. Use PHP’s setcookie () to create a cookie.

Use PHP’s setcookie () to create a cookie and a session that opens a session in PHP_ Like start(), there can be no HTTP header output before setcookie(). I went to check the code and found the following code

setcookie('qOpenId',$openid,time() + 30 * 24 * 3600,'/');

Decisively annotate var_ Dump ($openid) line, test, success.

Personally, setcookie should directly set the content in HTTP header, so there can’t be any header output in front, var_ Dump, echo and so on.

Knowledge point extension:



Parameter description

  • Name is required. Specifies the name of the cookie.
  • Value is required. Specifies the value of the cookie.
  • Expire is optional. Specify the validity period of the cookie.
  • Path is optional. Specify the server path of the cookie.
  • Domain is optional. Specifies the domain name of the cookie.
  • Secure is optional. Specifies whether cookies are transmitted over a secure HTTPS connection.

setcookie("webURL",, time()+3600*24);

This is the end of this article on how PHP handles setcookie invalidation. For more solutions to PHP setcookie invalidation, please search the previous articles of developeppaer or continue to browse the relevant articles below. I hope you will support developeppaer in the future!