Solved

remember me script

Posted on 2012-12-29
5
303 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

895 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

17 Experts available now in Live!

Get 1:1 Help Now