PHP permanent cookie

半世苍凉 提交于 2020-01-16 04:30:25

问题


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

Thanks!


回答1:


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.




回答2:


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)




回答3:


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



回答4:


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



回答5:


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



来源:https://stackoverflow.com/questions/6865259/php-permanent-cookie

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!