Jump to content

[SOLVED] Keep User Logged In Forever


Northern Flame

Recommended Posts

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.