I am using php code and trying to set cookies as shown below :
setcookie("_GuestID",$userID,time() + (20 * 365 * 24 * 60 * 60));
I found that cookies are expire just after close of browser. I want to make it persistent for long time.How I can do. Please give your suggestions.
Thanks
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.
There is no special way to set persistent cookies. Its the same way you set normal cookies. Cookies with an expiration date are called persistent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With