Page 1 of 1
Login Cookies???
Posted: Thu Oct 26, 2006 10:37 pm
by lip9000
I have setup a website and in the login page, currently users just login, and when they exit the browser, and then open it back up, they have to log in again.
How do I set it up so that when users log in, it creates a cookie on the computer remembering that they are logged in, so that when they close the browser and reopen it, they are still logged in?
Also how do I set it so that the cookie expires in 1 hour?
Thanks heaps.
Posted: Thu Oct 26, 2006 10:47 pm
by s.dot
Code: Select all
setcookie('whatever', 'whatever', time()+60*60);
Posted: Thu Oct 26, 2006 10:48 pm
by Zoxive
Code: Select all
setcookie("User_Login", $User, time()+3600); // Current Time + 3600 Seconds = 1 hr
edit: Dang you...
-NSF
Posted: Thu Oct 26, 2006 11:11 pm
by s.dot
NonStopableForce wrote:Code: Select all
setcookie("User_Login", $User, time()+3600); // Current Time + 3600 Seconds = 1 hr
edit: Dang you...
-NSF
hehe it's kinda cool. the "dang you" response because i helped someone a little bit quicker. shows a good spirit in the helping community! keep up the good work =]
Posted: Fri Oct 27, 2006 5:01 am
by lip9000
thanks! yeh i am new here sorry. ok so that goes in the login, and i should put in the users username and password variables into that cookie right??
then next how do i check if that cookie exists next time they come to the site??
Posted: Fri Oct 27, 2006 9:50 am
by pickle
Do not put the users password in the cookie! Setting cookies isn't necessarily secure.
In the scheme I've got set up - after the user logs in, they're given a session id. That session id along with their username is what's stored in a cookie. Then on every page load, I check that session id & see if its active & in the database.
To check if the cookie exists, just reference the $_COOKIE array:
Code: Select all
if(isset($_COOKIE['whatever I named my cookie']))
...
Though you should do more than just check if that cookie exists - you should also verify it's contents.