I wish to set a cookie that expires in 90 days using PHP, how could I do that? Thanks in advance.
You can extend the life of a cookie beyond the current browser session by setting an expiration date and saving the expiry date within the cookie. This can be done by setting the 'expires' attribute to a date and time.
Or you might use mktime(). time()+60*60*24*30 will set the cookie to expire in 30 days. If not set, the cookie will expire at the end of the session (when the browser closes). The path on the server in which the cookie will be available on.
PHP Create/Retrieve a Cookie The cookie will expire after 30 days (86400 * 30). The "/" means that the cookie is available in entire website (otherwise, select the directory you prefer).
name: The name of the cookie. value: The value you want to store in the cookie. expire-time: It is the number of seconds until the cookie will be kept on the user's machine by the browser. After that, it will automatically be deleted.
setcookie(name, value, time()+60*60*24*90);
This will set the cookie for 90 Days.
cookie expirations are set in seconds: so 60*60*24*90 would be 90 days
setcookie("MyCookie", $value, time()+(60*60*24*90));
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