remember me upon login

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

remember me upon login

Post by tomsace »

Hello,
I am having trouble with my remember me cookies on my login form.
I have managed to set the cookie (ish) but cannot seem to use it.

When the login form is submitted:

Code: Select all

$_SESSION['user'] = $username;  
 
$post_autologin = $_POST['autologin'];   
 
$value = "user=$username pass=$md5pass";
if($post_autologin == 1)  
    {  
    setcookie (RememberMe, $value, time() + 3600 * 24 * 30);  
    }   
This doesn't seem to be adding the value I am wanting, I want the value to be something like this:
user=USER123+pass=PASS123

But it is showing as
user%3DUSER123+pass%3DPASS123

Why arent the '=' symbols showing?

Now because of this I don't think my code to use the cookie works, In the header of the login page I have got:

Code: Select all

if (isset($_SESSION['user'])) 
{  
include_once 'autologin.php'; 
}
and autologin.php is:

Code: Select all

<?php   
        if(isset($_COOKIE[RememberMe]))
    {
    parse_str($_COOKIE[RememberMe]);
 
    if((user == $username) && (pass == $md5pass)))
        {
        // Register the session
        $_SESSION['user'] = $username;
        }
    }
?>
Of course I have set:

Code: Select all

if (isset($_SESSION['user']))
{
header("Location: /user/myaccount");
}
So hopefully if the cookie is read correctly the page is directed to the myaccount page...

I have been messing around with the codes now for a good 3 hours!!! I feel like im goind round in cirlces so I thought I should ask someone here before I go crazy!!! (First time using cookies by the way)...

Been using http://www.bitrepository.com/php-autologin.html to help me.
straightman
Forum Commoner
Posts: 48
Joined: Sun Apr 19, 2009 5:20 am

Re: remember me upon login

Post by straightman »

The syntax is not correct here:

$value = "user=$username pass=$md5pass";

you need to use '.' to separate entities of values.
Last edited by Benjamin on Tue May 26, 2009 10:22 am, edited 1 time in total.
Reason: Removed [quote] of entire op.
Post Reply