Canman2005 Posted November 18, 2008 Share Posted November 18, 2008 Hi all I have a members login page which is secured with SESSIONS, when you login a SESSION is created and that's what determins if you should see member content or not. I want to try and keep the member logged in for the MAXIMUM time possible, so even when they close a browser a re-open, it would remember them and they should not have to log in again. What do you feel is the best way to do this so that I can maximise the length of time they are logged in. Any advice would be ace Thanks Quote Link to comment https://forums.phpfreaks.com/topic/133176-keeping-logged-in-with-sessions/ Share on other sites More sharing options...
waynew Posted November 18, 2008 Share Posted November 18, 2008 Use Cookies. Quote Link to comment https://forums.phpfreaks.com/topic/133176-keeping-logged-in-with-sessions/#findComment-692599 Share on other sites More sharing options...
MasterACE14 Posted November 18, 2008 Share Posted November 18, 2008 However it's not the best idea to extend the session for a long period of time, For example if the user is at a Internet Cafe, then the next person who uses the computer they were on, will still have access to the previous users account. If they didn't clear there cookies. Quote Link to comment https://forums.phpfreaks.com/topic/133176-keeping-logged-in-with-sessions/#findComment-692609 Share on other sites More sharing options...
JasonLewis Posted November 18, 2008 Share Posted November 18, 2008 Which is why you make it an option when the user is logging in. Most forums have this option, a "Remember me on this computer" option. Just set the cookie if the checkbox is ticked. Quote Link to comment https://forums.phpfreaks.com/topic/133176-keeping-logged-in-with-sessions/#findComment-692615 Share on other sites More sharing options...
Canman2005 Posted November 18, 2008 Author Share Posted November 18, 2008 Thanks Guys, I thought cookies were the way to do it but just wanted to see what you thought. I've seen and tried many cookie stay logged in scripts, but never really managed to get one working well, do you know of any good tutorials on setting this up. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/133176-keeping-logged-in-with-sessions/#findComment-692620 Share on other sites More sharing options...
revraz Posted November 18, 2008 Share Posted November 18, 2008 Google Cookies and PHP, you'll find more than enough examples. Quote Link to comment https://forums.phpfreaks.com/topic/133176-keeping-logged-in-with-sessions/#findComment-692655 Share on other sites More sharing options...
Canman2005 Posted November 19, 2008 Author Share Posted November 19, 2008 Thanks, I have managed to get the following, but I get "Parse error: syntax error, unexpected T_STRING in C:\web\test.php on line 5" when its run, any ideas? $_POST['username'] = 'xx'; $_POST['pass'] = 'yy'; $hour = time() + 60*60*24*1000 setcookie("ID_my_site", $_POST['username'], $hour); setcookie("Key_my_site", $_POST['pass'], $hour); print $_COOKIE['ID_my_site']; print $_COOKIE['Key_my_site']; Thanks Quote Link to comment https://forums.phpfreaks.com/topic/133176-keeping-logged-in-with-sessions/#findComment-693781 Share on other sites More sharing options...
revraz Posted November 19, 2008 Share Posted November 19, 2008 forgot semi colon here $hour = time() + 60*60*24*1000; <---- Quote Link to comment https://forums.phpfreaks.com/topic/133176-keeping-logged-in-with-sessions/#findComment-693785 Share on other sites More sharing options...
premiso Posted November 19, 2008 Share Posted November 19, 2008 need a semi-colon after this line $hour = time() + 60*60*24*1000; Quote Link to comment https://forums.phpfreaks.com/topic/133176-keeping-logged-in-with-sessions/#findComment-693786 Share on other sites More sharing options...
Canman2005 Posted November 19, 2008 Author Share Posted November 19, 2008 Yes, thanks, managed to see that in the end. I am now using $timeset = time() + 60*60*24*1000; setcookie("cookie_ef_username", $_POST['email'], $hour); setcookie("cookie_ef_password", $_POST['password'], $hour); Which works fine until the browser is closed and then it seems to loose the cookie data, why could that be? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/133176-keeping-logged-in-with-sessions/#findComment-693794 Share on other sites More sharing options...
premiso Posted November 19, 2008 Share Posted November 19, 2008 Your not using the timeset anywhere in the cookie declaration or the browser is set to clear out all cookies... setcookie suggest reading the usage there. Quote Link to comment https://forums.phpfreaks.com/topic/133176-keeping-logged-in-with-sessions/#findComment-693795 Share on other sites More sharing options...
Jabop Posted November 19, 2008 Share Posted November 19, 2008 It's because you're using Windows. You got your $timeset confused with $hour. PS, browsers only support cookie lengths of 365 days long, otherwise the cookie expires immediately. Quote Link to comment https://forums.phpfreaks.com/topic/133176-keeping-logged-in-with-sessions/#findComment-693899 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.