Northern Flame Posted December 25, 2007 Share Posted December 25, 2007 I want to create an option on my members area where the user can stay logged in forever, I have never done this before but I came up with an idea, can anyone let me know if I am starting off good, and if I am not, can someone point me in the right direction? heres my idea: basically, if they want to stay logged on forever i will just track there ip address on my database <?php /* CHECK THE USERS LOGIN INFO HERE */ $forever = $_POST['forever']; //this is the checkbox the user checks if he wants to stay logged in if(!empty($forever)){ $ip = $_SERVER['REMOTE_ADDR']; //users ip address mysql_query("UPDATE users SET ip = '$ip' WHERE username='$username'"); } ?> im guessing that would work fine, but my problem is when the user returns to my website after already checking that he wants to stay logged in forever, how will i check for this? I know I can check my database and then just establish the session variables, but if each page is checking for the users return, each page will then have to re-establish the session variables right? can something like this work: <?php if(!isset($_SESSION['id'])){ $ip = $_SERVER['REMOTE_ADDR']; $check_login = mysql_query("SELECT * FROM users WHERE ip='$ip'"); if(mysql_num_rows($check_login) == 1){ // ESTABLISH SESSION VARIABLE } else{ echo 'You are not logged in!'; } } ?> is that a smart way of doing this? or is there a smarter way? Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 25, 2007 Share Posted December 25, 2007 http://www.phpnerds.com/article/using-cookies-in-php/2 study this ok Quote Link to comment Share on other sites More sharing options...
blueman378 Posted December 25, 2007 Share Posted December 25, 2007 and what about those people with a dynamic ip? there is no way to truly keep your user logged in forever but the most common way is to set the cookie to expire eg 10 years later, but this can still be gotten rid of when the user clears thier cookies, Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted December 25, 2007 Author Share Posted December 25, 2007 alright thanks for the tips, I will read that article right now Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted December 25, 2007 Author Share Posted December 25, 2007 alright i have read the article and i think i understand it, thanks for the help Quote Link to comment 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.