Solved

remember me script

Posted on 2012-12-29
5
301 Views
Last Modified: 2012-12-30
does anyone know how to do remember me only for the user name in the login?  I know it uses the cookies, but I have not had any luck getting it working; this is a linux app.....
0
Comment
Question by:Jack_son_
  • 2
  • 2
5 Comments
 
LVL 13

Assisted Solution

by:themrrobert
themrrobert earned 167 total points
ID: 38730251
This code will have no username in it the first time you try to log in, but after you log in once, subsequent visits to the page will automatically populate the username

<?php
/* Login.php */

//start session so php will remember stuff.
session_start();

if(isset($_REQUEST['username']) { 
   //a user is trying to login, save the username into session
   $_SESSION['username'] = $_REQUEST['username'];
   //do login code...
} else  {
   //get username from session and put in variable to use later
   $username = $_SESSION['username'];
    ?> 
<form action="<?php echo $PHP_SELF;?>" method="post">
<input type="text" name="username" value="<?php echo $username; ?>" />
<input type="password" name="password" />
<input type="submit" value="Login" />
</form>  
   <?php
}

?>

Open in new window

0
 

Author Comment

by:Jack_son_
ID: 38730268
Okay great, thanks;  Here is part of my code, I was going to add that before session cookie?  

<?php

require_once 'masters/options.php';
require_once 'masters/auditing.php';



function getAuthenticationTable() {
      return 'user_account';
}

function getSessionTable() {
      return 'user_session';
}

function getSessionLength() {
      return 15*60*1000; // 15 minutes
}

function getCookieSession() {
      return new Zend_Session_Namespace('Masters');
}
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 333 total points
ID: 38730704
This article explains it all:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html

The not-so-subtle difference between a PHP session and a "remember me" cookie is that the cookie can persist beyond the current session.  PHP garbage collection will cause the session to be lost after 24 minutes of inactivity (where activity is defined by an HTTP request).  And the PHP session cookie will be lost when the browser is closed.  Thus a persistent cookie is needed to connect the client to the existing profile on the server.
0
 

Author Comment

by:Jack_son_
ID: 38730756
Great post and explanation; the remember me function is line 57 to 123?  

// DEFINE THE "REMEMBER ME" COOKIE FUNCTION
function remember_me($uuk)
{
    // CONSTRUCT A "REMEMBER ME" COOKIE WITH THE UNIQUE USER KEY
    $cookie_name    = 'uuk';
    $cookie_value   = $uuk;
    $cookie_expires = time() + date('Z') + REMEMBER;
    $cookie_path    = '/';
    $cookie_domain  = NULL;
    $cookie_secure  = FALSE;
    $cookie_http    = TRUE; // HIDE COOKIE FROM JAVASCRIPT (PHP 5.2+)

    // SEE http://us3.php.net/manual/en/function.setcookie.php
    setcookie
    ( $cookie_name
    , $cookie_value
    , $cookie_expires
    , $cookie_path
    , $cookie_domain
    , $cookie_secure
    , $cookie_http
    )
    ;
}



// DETERMINE IF THE CLIENT IS ALREADY LOGGED IN BECAUSE OF THE SESSION ARRAY
if (!isset($_SESSION["uid"]))
{

    // DETERMINE IF THE CLIENT IS ALREADY LOGGED IN BECAUSE OF "REMEMBER ME" FEATURE
    if (isset($_COOKIE["uuk"]))
    {
        $uuk = mysql_real_escape_string($_COOKIE["uuk"]);
        $sql = "SELECT uid FROM EE_userTable WHERE uuk = '$uuk' LIMIT 1";
        $res = mysql_query($sql);

        // IF THE QUERY SUCCEEDED
        if ($res)
        {
            // THERE SHOULD BE ONE ROW
            $num = mysql_num_rows($res);
            if ($num)
            {
                // RETRIEVE THE ROW FROM THE QUERY RESULTS SET
                $row = mysql_fetch_assoc($res);

                // STORE THE USER-ID IN THE SESSION ARRAY
                $_SESSION["uid"] = $row["uid"];

                // EXTEND THE "REMEMBER ME" COOKIE
                remember_me($uuk);
            }
        }
    }
}
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 333 total points
ID: 38730821
Technically speaking the remember_me() function is line 57-80 of the config script.  It is called on line 31 of the login script, line 38 of the register script, etc.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now