Bạn đang xem: How do you update a cookie in php?
How bởi you update an existing cookie?
i.e. setcookie("cookie_name", "cookie_value", time()+3600, "/");
A suggested expiration time for the 3rd argument:
$exp_time = time()+3600; /* expire in 1 hour */$exp_time = time()+86400; /* expire in 1 day */It works. Be sure khổng lồ read "Common Pitfalls" from that page.
You can use the super global $_COOKIE<"cookie_name"> as well khổng lồ read cookies.
Xem thêm: Làm Sao Để Biết Ung Thư Di Căn Xương ? Ung Thư Di Căn Xương Là Gì
There should be a line lượt thích below in php vps 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
So while PHP will send two Set-Cookie: headers if instructed so, only the last one should persist in browsers.The Netscape cookie spec http://curl.haxx.se/rfc/cookie_spec.html says:
Instances of the same path & name will overwrite each other, with the latest instance taking precedence. Instances of the same path but different names will địa chỉ additional mappings.
However, it might be advisable lớn avoid such edge conditions. Restructure your application so it doesn"t need lớn override the already sent cookie.
Thanks for contributing an answer to Stack Overflow!
Please be sure to lớn answer the question. Provide details và share your research!But avoid …
Asking for help, clarification, or responding khổng lồ other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.
By clicking “Post Your Answer”, you agree lớn our terms of service, privacy policy và cookie policy
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device & disclose information in accordance with our Cookie Policy.