[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

remember me script

Posted on 2012-12-29
5
Medium Priority
?
312 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 13

Assisted Solution

by:themrrobert
themrrobert earned 668 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1332 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 111

Accepted Solution

by:
Ray Paseur earned 1332 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

656 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