I Am Chris Posted August 3, 2008 Share Posted August 3, 2008 Best case scenerio is that people can log in, and have cookies set for, lets say 15 minutes. after 15 minutes they will be logged out, but it is refreshed as long as their active, or whenever they do something, ect. is there a way i can do this? otherwise i'm going to have to use sessions, and cookies just for remember me function. so, is there a way to frequently refresh cookies? Link to comment https://forums.phpfreaks.com/topic/117903-can-i-refreash-cookies/ Share on other sites More sharing options...
Stooney Posted August 3, 2008 Share Posted August 3, 2008 First off, sessions are probably the better bet for a login system. If you want to use cookies, you could just remake the cookie at the top of your index.php (or whatever file is always loaded). Link to comment https://forums.phpfreaks.com/topic/117903-can-i-refreash-cookies/#findComment-606489 Share on other sites More sharing options...
JasonLewis Posted August 3, 2008 Share Posted August 3, 2008 I'd recommend you use sessions anyway. You can do a timeout with sessions. Check this sample script out: //Lets check if the user is logged in first. if(isset($_SESSION['user_is_logged'])){ if(!isset($_SESSION['timeout'])){ //The session isn't even set, but they are logged in. So lets set the session $_SESSION['timeout'] = time() + (60 * 15); //This sets the timeout to 15 minutes from now... Change 15 to however many minutes... }else{ //The session is set. Lets check if they have been inactive for too long. $timeout = $_SESSION['timeout']; if(time() > $timeout){ //The current time() is greater then what then what there timeout is. That is, its been at least 15 minutes since they have refreshed. So now lets log them out! session_destroy(); //You can also remove cookies here too if you need too.. }else{ //If we got here, it means the user refreshed but they were not inactive for 15 minutes. So lets update the timeout session. $_SESSION['timeout'] = time() + (60 * 15); //This sets the timeout to 15 minutes from now... Change 15 to however many minutes... } } } Okay, basically that example script sets a session called timeout to 15 minutes into the future. Then every time the user reloads the page we check to see if the current time is greater then what we set timeout to. If it is, they were inactive for too long, if it isn't... Well, they are being active. If they were inactive too long we log them out. If they are still active then update the timeout session, and set it for another 15 minutes into the future. Hope that makes sense and I understood your question correctly. Good luck. Edit: Just changed the code slightly. Link to comment https://forums.phpfreaks.com/topic/117903-can-i-refreash-cookies/#findComment-606490 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.