Adding a "Remember Me" feature

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello, I have a simple login script.  I have the pages


What I want to do is have a checkbox on the login.php page where if the
user checks it and logs in successfully, upon closing the browser and
returning to the login.php page, they are automatically redirected to
the login_success.php page.  What must I do to accomplish this?

Thanks for your help, - Dave

Re: Adding a "Remember Me" feature

On the login_success page, check to see whether they checked "remember
me".  If they did, set either a cookie or a session variable (if your
sessions are set not to expire too fast) that remembers that the person
has been authorized.  Then on login.php, check for the cookie or
session variable.  If they have it, redirect them to the login_success
page like this:
header('Location: ');

Re: Adding a "Remember Me" feature


First of all check user has checked remember me feature checkbox by
$_POST['remember'] or whtever name u have given to checkbox

Second if user checked and u get Post value then set two cookies on the
user's computer. that contains two important pieces of information: the
username and the encrypted password.  Set cookies  expiry time say 100
days, after which the cookie will be deleted. However, it also gets
deleted when the user decides to log out

then whenever user logged in check as above:

if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookpass'])){
      $_SESSION['username'] = $_COOKIE['cookname'];
      $_SESSION['password'] = $_COOKIE['cookpass'];
and if he had checked remember me feature then  store value as:

      setcookie("cookname", $_SESSION['username'], time()+60*60*24*100,
      setcookie("cookpass", $_SESSION['password'], time()+60*60*24*100,

to be checked next time user login.

and then perform rest of the task.


Re: Adding a "Remember Me" feature

Kimmo Laine wrote:
Quoted text here. Click to load it

Unless next_page.php generates PHP, the script with this include will
only get HTML.

Quoted text here. Click to load it


    if (isset($_GET['foo'])) {
      echo '<?php echo $_GET[\'foo\']; ?>';
    } else {
      echo '<?php echo \'Not available\'; ?>';

File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

Site Timeline