Solved

remember me script

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

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 109

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
android secure ftp 3 35
ignore other .htaccess 2 44
Scroll 5 news at a time. 4 26
PHP Syntax Error 4 26
Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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…
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…

776 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