Sometimes, while working with Cookies in PHP you may want to make a cookie never expire (e.g. in a rating script where you set a cookie on user’s computers, although it’s not wise to use cookies as the only protection against multiple ratings by the same user, because cookies are easily deleted). Unfortunately, the setcookie() function does not have a specific argument for the expiration to be “never”, but you can set an expiration date in the distant future to achieve this.

For example:


[ad name=”In Post (LU)”]

Where 60*60*24*365*10 is equal to:
10 years = 60 seconds * 60 minutes * 24 hours * 365 days * 10 years

So to make a cookie expire in 50 years for example you would just need to modify the 10 at the end and the PHP snippet will look like this:


Done! Now you have a PHP cookie that never expires (or at least it will outlive your computer).

Leave a Reply

Your email address will not be published. Required fields are marked *