Permanent Login
How can I have pe开发者_JAVA技巧rmanent login of the people who log in to my site (Even if the browser is turned off) until they log out.
Use longterm cookies to identify your users.
Example:
setcookie('site_user', '<secure_hash>', time()+(3600*24*7)); //expire in a week
Notice, this technique involves security problems.
CCCCCCCCCCCCCCCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOKKKKKKKKKKKKKKKKKKKKKKKKKKIIIIIIIIIIIIIIIIIEEEEEEEEEEEEEEEEEEEE!
Yeah, you'll be wanting to check out cookies, particularly the expire parameter, you can read about it here: http://www.php.net/manual/en/function.setcookie.php
Hope this helps.
just to expand as you dont want them to logout
erenon's code on your login page changed to support a year
setcookie('site_user', '<secure_hash>', time()+(3600*24*7*52)); // now a year
this code on every page it will always refresh the cookie if its there to create the never expire now if they log out for a year is the only time they wont stay logged in
if(isset($_COOKIE['site_user'])){
setcookie('site_user', $_COOKIE['site_user'], time()+(3600*24*7*52));
}
精彩评论