|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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! |
|
#3
|
|||
|
|||
|
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? |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
i'm getting myself confused.
so how exactly would i set the cookie and how do i do the sessions? |
|
#6
|
|||
|
|||
|
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.
|
|
#7
|
|||
|
|||
|
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); } |
|
#8
|
|||
|
|||
|
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. |
|
#9
|
|||
|
|||
|
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? |
|
#10
|
|||
|
|||
|
Quote:
You can simply check: if (isset($_COOKIE["USERNAME"])) { // code here to process } |
|
#11
|
|||
|
|||
|
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:
<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"> </td> </tr> <tr align="left" valign="middle"> <td width="93">Password:</td> <td width="149"> <input type="password" name="pass"> </td> <td width="158"> </td> </tr> <tr align="left" valign="middle"> <td width="93"> </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> |
|
#12
|
|||
|
|||
|
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:
|
|
#13
|
||||
|
||||
|
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > remember me login |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|