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.
Login Cookies???
Moderator: General Moderators
Code: Select all
setcookie('whatever', 'whatever', time()+60*60);Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Code: Select all
setcookie("User_Login", $User, time()+3600); // Current Time + 3600 Seconds = 1 hredit: 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 =]NonStopableForce wrote:Code: Select all
setcookie("User_Login", $User, time()+3600); // Current Time + 3600 Seconds = 1 hr
edit: Dang you...
-NSF
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
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:
Though you should do more than just check if that cookie exists - you should also verify it's contents.
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']))
...Real programmers don't comment their code. If it was hard to write, it should be hard to understand.