I want to manage a username session for lifetime. means for example if u look a website http://www.kongregate.com/ in this website i have registered and i haven't logged out but whenever i open up this website my username appears there. No need to login again. so i want to do the same for my one of the games website. i hav开发者_JAVA技巧e developed my website using php mysql flash. Can anyone please guide me?
Regards, phphunger.
Try setting a cookie this way :
setcookie("LoginCookie", $value, time()+$seconds);
where $seconds is a big number eg 3 years (3*365*24*60*60).
and on your pages check if the cookie still exists :
if(isset($_COOKIE["TestCookie"])) ...
I think what you're looking for is storing a cookie on the user's machine.
http://en.wikipedia.org/wiki/HTTP_cookie
a quick google search for "PHP Cookie tutorial" turned up a couple results.
http://www.tizag.com/phpT/phpcookies.php
edit: I should add that you should look up things specific to authentication cookies if using this to bypass user login. You don't want someone editing the cookie for your site and just changing the username to allow them to login as someone else.
Write a cookie on the client's machine and set its expiration date to 'never'. One thing you should know that if the user delete's his/her cookies/temp files then they'll be required to log in again.
精彩评论