How to set persistent cookie
cookies, php
Solution
As has already been noted, check if the cookie is actually being set in your browser (your syntax appears correct).
Cookies will only persist for as long as you have set them. I've always used a year as a round period unless there are specific expiry requirements (which are usually much shorter).
Use the strtotime function to make them easier to read:
setcookie( "cookieName1", $value1, strtotime( '+1 year' ) );
setcookie( "cookieName2", $value2, strtotime( '+30 days' ) );
There are many examples of how to use them on the setcookie manual page which is worth taking the time to read.
Problem
I am using this PHP code and trying to set cookies as shown below: ``` setcookie("_GuestID",$userID,time() + (20 * 365 * 24 * 60 * 60)); ``` I found that cookies expire just after closing the browser. I want to make it persistent for a long time. How I can do?