PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 22nd, 2003, 11:17 AM
klink klink is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 31 klink User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
remember me login

i was browsing around here and i noticed a couple of topics about php login scripts with a remember me checkbox. i've been working on one myself, but i'm not familiar with cookies in php so i havn't been able to make heads or tails of what i've read in here.
i'm not running mysql on the server that my script will be used on. instead, i'm saving my usernames and passwords in a php file called info.inc
i know how to call my values stored in the info.inc file and compare them with the user input, but i don't know how to set a cookie, and i don't know how to set the cookie so that when the user returns they will be auto logged in.
thanks for your help

Reply With Quote
  #2  
Old October 22nd, 2003, 12:55 PM
kab01nk kab01nk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 5 kab01nk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
To set a cookie, you can use:

setcookie("NAME", "VALUE", time() + 1200, "/");

This will set a cookie with the name of NAME and a value of "VALUE." It will expire in 20 minutes.

What I do is if they choose to be "remembered", then I set the the value of their ID. IF/when their session expires, check if the cookie exists, and, if so, relog them back in. I use it with a MySQL db, but the principle should work fine for you.

HTH!

Reply With Quote
  #3  
Old October 22nd, 2003, 01:20 PM
klink klink is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 31 klink User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
how do i check for the existance of the cookie?
how do i check to see if it has expired?
how do i reactivate it once it has expired?

Reply With Quote
  #4  
Old October 22nd, 2003, 01:34 PM
kab01nk kab01nk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 5 kab01nk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
If you're using sessions, you should have a default set (as in a members ID, defaulted to 0). You can check it by:

if (!$_SESSION["ID"] && isset($HTTP_COOKIE_VARS["MEMID"])) {
// code to relookup the ID from the value in the cookie
}

HTH.

Reply With Quote
  #5  
Old October 22nd, 2003, 01:54 PM
klink klink is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 31 klink User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
i'm getting myself confused.
so how exactly would i set the cookie and how do i do the sessions?

Reply With Quote
  #6  
Old October 22nd, 2003, 02:26 PM
kab01nk kab01nk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 5 kab01nk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How do you currently track how the user is logged in? We should start from there. Post some code so we can see what/how you're doing it.

Reply With Quote
  #7  
Old October 22nd, 2003, 04:12 PM
klink klink is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 31 klink User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
ok here is what i've got
the log on page has the username and password text boxes with a checkbox for the remember me option. the form is a post form
when you hit submit, it reloads the logon page. this code is at the top.
<?php
//check for submit
if ($HTTP_POST[$Submit])
{
include ("info.inc");
for ($x=0; $x<3; $x++)
{
if (($HTTP_POST[$name] == $username[$x]) && ($HTTP_POST[$pass] == $password[$x]))
{
//code here will redirect site according to user
}
}
}

?>

the info.inc file as 2 arrays. one for use names and 1 for passwords. i know this isn't the best way to do this, but i'm just doing it this way for right now.

this is what i need for the cookie i think...... but i'm not sure where to put it.
if($HTTP_POST['the check box'] == "on")
{
$time_expire = time()+5184000;
setcookie("the user name", "the password", $time_expire);
}

Reply With Quote
  #8  
Old October 22nd, 2003, 04:25 PM
kab01nk kab01nk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 5 kab01nk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Try:

if (($HTTP_POST[$name] == $username[$x]) && ($HTTP_POST[$pass] == $password[$x]))
{
// see if they asked to be remembered
if (isset($_POST["the check box"])) {
$time_expire = time()+5184000;
setcookie("USERNAME", $username[$x], $time_expire);
setcookie("PASSWORD", $password[$x], $time_expire);
}
}

The check box is only set if they check it. If they don't, it doesn't exist on the page.

HTH.

Reply With Quote
  #9  
Old October 22nd, 2003, 04:54 PM
klink klink is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 31 klink User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
ok that looks like it will work, but how to i check to see if the cookie is there to auto login the user?

and after that, how to i encript the cookie values so no one else can get ahold of them?

Reply With Quote
  #10  
Old October 22nd, 2003, 04:57 PM
kab01nk kab01nk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 5 kab01nk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by klink
ok that looks like it will work, but how to i check to see if the cookie is there to auto login the user?


You can simply check:

if (isset($_COOKIE["USERNAME"])) {
// code here to process
}

Reply With Quote
  #11  
Old October 23rd, 2003, 11:00 AM
klink klink is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 31 klink User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
man i'm so freaking screwed up........
i can't tell what is going on. here is my script. when i enter the user name and password and press subit, i have a debugging that echos it was submitted, but i also have debugging to echo the name and password eneter. it doesn't echo the name and password. instead of redirecting to the location listed, it echos the page was submitted and has the normal username and password text boxes. i'm not really sure what is going on. if anyone would like to help me with this or just totaly write me a new script, i'd be really greatful.

PHP Code:
<?php
if (isset($Submit))
{
    echo
"it was submitted\n";
    echo 
"$HTTP_POST_VARS[$name] $HTTP_POST_VARS[$pass]";
    
//include("info.inc");
    
$username = array("bigvalue","ctc","celledge");
    
$password = array("bgpass","ctcpass","cellpass");
    for (
$x=0$x<3$x++) 
    { 
        if ((
$HTTP_POST_VARS[$name] == $username[$x]) && ($HTTP_POST_VARS[$pass] == $password[$x])) 
        { 
            
// see if they asked to be remembered 
            
if (isset($HTTP_POST_VARS[$checkbox]))
            { 
                
$time_expire time()+5184000;
                
//setcookie ("TestCookie", "", time() - 3600, "/clients/", ".cellulink.com", 0);
                
setcookie ("client"$username[$x], $time_expire"/clients/"".cellulink.com"0); 
                
setcookie ("pswrd"$password[$x], $time_expire"/clients/"".cellulink.com"); 
            }
            
$url "log.php?client=$username[$x]";
            
header("Location: $url");
        }
    }
}
else if (isset(
$HTTP_COOKIE_VARS["client"]))
{
    
$username $HTTP_COOKIE_VARS["client"];
    
$url "log.php?client=$username";
    
header("Location: $url");
}




?>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="index.php">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr align="left" valign="middle">
<td width="93">User Name:</td>
<td width="149">
<input type="text" name="name">
</td>
<td width="158">&nbsp;</td>
</tr>
<tr align="left" valign="middle">
<td width="93">Password:</td>
<td width="149">
<input type="password" name="pass">
</td>
<td width="158">&nbsp;</td>
</tr>
<tr align="left" valign="middle">
<td width="93">&nbsp;</td>
<td width="149">
<input type="submit" name="Submit" value="Log In">
<input type="reset" name="Submit2" value="Reset">
</td>
<td width="158">
<input type="checkbox" name="checkbox" value="checkbox">
Remember Me</td>
</tr>
</table>
</form>
</body>
</html>

Reply With Quote
  #12  
Old October 23rd, 2003, 01:06 PM
klink klink is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 31 klink User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
i just went back through my code and it is really sloppy. i found some sytacs errors and stuff and i corrected that. everything is working on it now BUT i cann't delete my cookies if a user wished to log out. here is my logout script and it doesn't delete the cookies!!!!!
PHP Code:
 $time_expire time()-9999999999;
$username $HTTP_COOKIE_VARS[name];
$password $HTTP_COOKIE_VARS[pswrd];
setcookie ("name"""$time_expire"/folder/"".mydomain.com"0); 
setcookie ("pswrd"""$time_expire"/folder/"".mydomain.com");
unset( 
$HTTP_COOKIE_VARS[name]);
unset( 
$HTTP_COOKIE_VARS[pswrd]);
print 
"<META HTTP-EQUIV='Refresh' content='0;URL=index.php'>"

Reply With Quote
  #13  
Old October 23rd, 2003, 05:36 PM
codergeek42's Avatar
codergeek42 codergeek42 is offline
[Insert clever comment here.]
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jul 2003
Location: Anaheim, CA (USA)
Posts: 6,459 codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)  Folding Points: 39542 Folding Title: Starter FolderFolding Points: 39542 Folding Title: Starter Folder
Time spent in forums: 1 Month 1 Week 6 Days 21 h 41 m 44 sec
Reputation Power: 1231
Send a message via ICQ to codergeek42 Send a message via AIM to codergeek42 Send a message via Yahoo to codergeek42 Send a message via Google Talk to codergeek42

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > remember me login


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump