How do you update a cookie in PHP?

前端 未结 5 1976
清酒与你
清酒与你 2020-12-30 23:06

If I call setcookie() two times with the same cookie name, I get two cookies created.

How do you update an existing cookie?

5条回答
  •  鱼传尺愫
    2020-12-30 23:23

    Make sure there is no echo before setcookie call. setcookie communicates with browser through header, and if you called echo earlier, header+body is sent already and server cannot send setcookie to browser via header anymore. That is why you might see it is not working.

    There should be a line like below in php server log file reporting warning in this case:

    DEFAULT: PHP Warning:  Cannot modify header information - headers already sent by (output started at /path/to/your/script.php:YY) in /path/to/your/script.php on line XX
    

提交回复
热议问题