DiegoP.
DiegoP.

Reputation: 45757

PHP permanent cookie

How do I set up a cookie that won't never expire, even when the user closes his browser or stops his machine?

Thanks!

Upvotes: 2

Views: 17703

Answers (5)

JK.
JK.

Reputation: 5136

The user will always have the option to remove or block cookies. But you can always set the expire date in the far future.

Upvotes: 0

Emil Condrea
Emil Condrea

Reputation: 9983

setcookie("cname" ,$value, mktime (0, 0, 0, 12, 31, 2015));

Upvotes: 0

user562854
user562854

Reputation:

You can assign a expiration date which is very far from now:

setcookie("testCookie","value",mktime (0, 0, 0, 12, 31, 2015));
//Expires on 31 december 2015

Upvotes: 2

Phil
Phil

Reputation: 11175

setcookie("example", $cookievalue, time()+60*60*24*6004, "/", ".example.com");

Impossible to set a cookie forever, browsers wouldn't allow that. (ps. it's amazing what wonders google will conjure up if you were to literally google the title of this question)

Upvotes: 2

barfoon
barfoon

Reputation: 28187

I don't think there is a way to have a 'permanent' cookie, but rather one that expires very very far into the future. Just because you remained logged into a website/service the next time you return or after you close your browser, does not mean that there is no expiration date on the cookie.

Check out the PHP documentation on setting the lifetime of a cookie.

Upvotes: 5

Related Questions