On some sites, like facebook, gmail, youtube, etc, you can tick this option (or it's like that by default) to be logged in infinitely, until you logout.
You can come back in days and you're still logged in. How does this work?
I'm working with session_start();
and storing the user data for example in
$_SESSION['user']['id'] = 40;
How do I change this code so that my user can stay logged in until they decide to log out开发者_JAVA技巧?
You can store user information in cookies, so they stay for until you need them. and every time user visits your site, you can check for it, and initialize new session based on your cookie information.
setcookie(name,value,expire,path,domain,secure)
If I recall in the PHP config file you can set the session lifetime to 0, however the session will expire when the user exists their browser.
You will have to use setcookie()
and set a high expire time like 9999999 (116 days). The problem with client-side cookies vs. sessions is that "client-side" cookies aren't good for storing sensitive items like password hashes.
精彩评论