Question about 'Remember Me' cookies on user logins - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Programming > PHP Development

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-04-2011, 02:27 PM   #1 (permalink)
Junior Member
 
Join Date: Aug 2011
Posts: 1
Default Question about 'Remember Me' cookies on user logins

Hi, I've been reading this forums for a while but this is my first post here. I've done much googling before finally deciding to post for help, so this is my last option.

I'm making a login script and I've got the session to work fine, but I can't seem to get my cookie to save. I can't find my mistake either, so hopefully someone can point out what I am doing wrong?

This is my code in the login.php:
PHP Code:
$username       =       $_POST['username'];
$pass           =       $_POST['password'];
$remember       =       $_POST['remember'];
 
 
        
$result user_login($username$pass);
       
        if (
$result != FALSE) {
                
//-- Login Succesful
                
$password       =       md5($pass);
                
$_SESSION['stillLogged'] = '1';
                
$_SESSION['userName']   =       $username;
                
$_SESSION['userPass']   =       $passwrod;
                if (
$remember == '1') {
                        
setcookie("cookuser_1"$_SESSION['userName'], time() + 60*3);
                        
setcookie("cookpass_1"$_SESSION['userPass'], time() + 60*3);
                        }
                echo 
'LOGGED IN SUCCESSFULL';
        } else {
                
//-- Login Failed
                
echo 'LOGGED IN FAILURE';
        } 
This is the login form code. It checks for session/cookie. If there isn't either set, it displays the login form. If a session is set, is shows successful login. If a cookie is set, it will use the information stored to log in automatically for the user. I removed all the html as it's not needed in my question, so I just made notifications where necessary.
PHP Code:
if((!isset($_SESSION['stillLogged'])) && (!isset($_COOKIE['cookuser_1'])))  {
       
        echo 
'User not logged in. Display login form.';
} elseif (isset(
$_SESSION['stillLogged'])) {
        
$userName       =       $_SESSION['userName'];
        echo 
'You are logged in as: '$userName;
} elseif (isset(
$_COOKIE['cookuser_1'])) {
        
$username       =       $_COOKIE['cookuser_1'];
        
$pass           =       $_COOKIE['cookpass_1'];
 
        
$result user_login($username$pass);
       
        if (
$result != FALSE) {
                
//-- Login Successful
                
$_SESSION['stillLogged'] = '1';
                
$_SESSION['userName']   =       $username;
               
                echo 
'SUCCESSFUL LOGIN';
        } else {
                
//-- Login Failed
                
echo 'LOGIN FAILURE';
        }
       
        } 
Now, my sessions work fine. But once I exit my browser, go back to the login page, it should use the cookie information to log me in, but does not. It displays the login form, which means that a cookie isn't set. I've used sessions before, but I am now trying to teach myself cookies(I'm fairly new to PHP, I'm trying to self-teach).

Am I way off? or have I made a small mistake that is easily fixed? And I'm aware I only have it set for 180 seconds, this is temporary as I am just trying to get this to work.

Last edited by mac08; 08-04-2011 at 02:30 PM.
mac08 is offline   Reply With Quote
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 04:56 PM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting