Jump to content

Remember Me Script


Superian

Recommended Posts

I need some help. I was thinking maybe someone could

help me get started with a script. I am not asking for

anyone to write it for me. I was just needing for someone

to explain to me what I will need for the script.

 

I am trying to create a script that will keep the user logged on

if the selected checkbox is checked during login. Will I need a extra column

in the database for this or what? I just need for someone to start

me off!! Thanks in advance!

 

Link to comment
https://forums.phpfreaks.com/topic/49133-remember-me-script/
Share on other sites

You could possibly make a column in your database that if the user checks "yes" on the "remember me" button, it will change it's value to "yes".

 

If the value is yes, then in a column right next to is will store an IP address, and if the IP Address is equal to the visitor, then it will log him in with the proper username etc.

 

Although, I recommend using cookies to do this, there are very easy tutorials on setting cookies, it can be done within minutes.

Link to comment
https://forums.phpfreaks.com/topic/49133-remember-me-script/#findComment-240725
Share on other sites

Look at here http://zigmoyd.sourceforge.net/man/ums.php#sign_in

And look at the

if($chk)
 {
   $getdb->remember();//Remembers User name and password//Uses Sessions
   echo "Login Successfull\n";
 }

But Please dont read only this read the installation and Using instrusctions also on http://zigmoyd.sourceforge.net/man/index.php

Click on the Download and you will find Some Video examples also there. And there is also some Classes for sign Up and Sign Out and many more things.

Link to comment
https://forums.phpfreaks.com/topic/49133-remember-me-script/#findComment-240905
Share on other sites

I am trying to create the Remeber me feature

using cookies but I am unable to to get the user

to login. I donnot want anyone to write it for me

just point out the scripts that may need to be change.

 

The first code is the login script and the second script is

just two functions that is used in the login script.

 

<?php
session_start();

if (isset($_POST['sublogin'])) // Name of attribute 

// they have just tried logging in
{
    $user_name= trim($_POST['user_name']);
    //$password = trim($_POST['password']);

   // Checks that username is in database and password is correct 
   //$password_str = md5($_POST['password']);
   $result = login($user_name); /*, $password_str*/

   // Check error codes 
   if($result == 0){
      // unsuccessful login
      do_html_header("Problem:");
      echo "<p class='genmed'>You could not be logged in. 
            You must be logged in to view this page.</p>";
  echo "<p class='genmed'> $user_name $password</p>";
      do_html_url("login.php", "Login");
      do_html_footer();
      exit;
   }   
   
   // if they are in the database register the user id
   $valid_user = $user_name;
   $_SESSION['valid_user'] = $valid_user;
   //$_SESSION['password'] = $password_str; 
   
    /**
    * This is the cool part: the user has requested that we remember that
    * he's logged in, so we set two cookies. One to hold his username,
    * and one to hold his md5 encrypted password. We set them both to
    * expire in 100 days. Now, next time he comes to our site, we will
    * log him in automatically.
    */
   if(isset($_POST['remember'])){
      setcookie("cookname", $_SESSION['user_name'], time()+60*60*24*100, "/");
      //setcookie("cookpass", $_SESSION['password'], time()+60*60*24*100, "/");
   }

   // Quick self-redirect to avoid resending data on refresh 
   echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[php_SELF]\">";
   return;
   
}

function displayLogin(){
   global $logged_in;
   if($logged_in){
     echo "<h1>Logged In!</h1>";
     echo "Welcome <b>$_SESSION[user_name]</b>, you are logged in. <a href=\"logout.php\">Logout</a>";
   }
   else{ header("Location: login.php"); }
}
?>

 

<?php
function login($user_name)/*, $password*/
// check username and password with db
// if yes, return true
// else return false
{
  // connect to db
  $conn = db_connect();
  if (!$conn)
    return 0;

  // Add slashes if necessary (for query) 
  if(!get_magic_quotes_gpc()) {
$user_name = addslashes($user_name);
  }
  
  // check if username is unique
  $query = "SELECT * FROM members_info WHERE  user_name='$user_name'"; //AND password=MD5('$password')";
  $result = mysql_query($query,$conn);
  if (!$result)
     return 0;
  
  if (mysql_num_rows($result)>0)
     return 1;
  else 
     return 0;
}

function check_valid_user()
// see if somebody is logged in and notify them if not
{
  // Check if user has been remembered 
  if(isset($_COOKIE['cookname']) ){    /*&& isset($_COOKIE['cookpass'])*/
      $_SESSION['valid_user'] = $_COOKIE['cookname'];
      //$_SESSION['password'] = $_COOKIE['cookpass'];
  }
  
  // Username and password have been set 
   if(isset($_SESSION['valid_user']) ){    /*&& isset($_SESSION['password'])*/
      // Confirm that username and password are valid 
      if(login($_SESSION['valid_user']) != 0){   /*, $_SESSION['password'])*/
         // Variables are incorrect, user not logged in 
         unset($_SESSION['valid_user']);
         //unset($_SESSION['password']);
         return false;
      }
      return true;
   }
   // User not logged in 
   else{
      return false;
   }
}

?>

Link to comment
https://forums.phpfreaks.com/topic/49133-remember-me-script/#findComment-241119
Share on other sites

If you are using cookies, do something that checks if the user checked the remember me, if checked set the cookie timeout to be some absurd amount like a year. If the checked box is unchecked set it to a day or so.

 

All you need it to do is set the cookie timeout to be that.

 

If you want to store it in session. Simply store a variable called logintime that shows then they logged in and have another option that is howlong which is the time of the end date.

 

If they checked the remember me set the howlong to be a year from now, if not than set it to be in a day or whatever and just check those 2 variables each time a page is ran.

 

The downside to the sessions is that they do expire once a page is closed so you may want to store the session data in a DB for a user and instantiate that session once they come back on.

 

Hope that helps.

Link to comment
https://forums.phpfreaks.com/topic/49133-remember-me-script/#findComment-241122
Share on other sites

If you are using cookies, do something that checks if the user checked the remember me, if checked set the cookie timeout to be some absurd amount like a year. If the checked box is unchecked set it to a day or so.

 

All you need it to do is set the cookie timeout to be that.

 

If you want to store it in session. Simply store a variable called logintime that shows then they logged in and have another option that is howlong which is the time of the end date.

 

If they checked the remember me set the howlong to be a year from now, if not than set it to be in a day or whatever and just check those 2 variables each time a page is ran.

 

The downside to the sessions is that they do expire once a page is closed so you may want to store the session data in a DB for a user and instantiate that session once they come back on.

 

Hope that helps.

 

LOL, I not that advance, I wish and Thanks for the response.

 

I have a checkbox with an attribute name="remember"

<?php
  /**
    * This is the cool part: the user has requested that we remember that
    * he's logged in, so we set two cookies. One to hold his username,
    * and one to hold his md5 encrypted password. We set them both to
    * expire in 100 days. Now, next time he comes to our site, we will
    * log him in automatically.
    */
   if(isset($_POST['remember'])){
      setcookie("cookname", $_SESSION['user_name'], time()+60*60*24*100, "/");
      //setcookie("cookpass", $_SESSION['password'], time()+60*60*24*100, "/");
   }
?>

Link to comment
https://forums.phpfreaks.com/topic/49133-remember-me-script/#findComment-241128
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.