Hi,
I'm writing a login script which will set a cookie and remember the person for next login.
I was able to get the first part; setting the cookie to work.
I am having a lot of trouble getting the remember part to work. I want the username and/or password remembered so the person doesn't have to reenter it every time.
My login form contains the following: <input type="checkbox" name="remember" value="Yes">.
I thought, that if I wrote the following statement, the information for the user should be remembered, but it's not:
if ($_POST[remember] == "Yes")
{
setcookie('member', 'member', time()+24360060);
}
How could I modify my script to make the above statement to work?
Please note: The code on the bottom doesn't include the above statement because no matter where I stick it, it won't work. So, I left the script at the point where it is working with setting the cookie.
Thanks for the help.
Here's the script:
<?php
session_start();
header("Cache-control: private");
include "conn.inc.php";
switch($_REQUEST['req'])
{
case "validate":
$validate = mysql_query("SELECT * FROM member WHERE
username = '{$POST['username']}' AND password = md5('{$POST['password']}')") or
die (mysql_error());
if (mysql_num_rows($validate) == 1)
{
while($row = mysql_fetch_assoc($validate))
{
$SESSION["status"] = "Logged";
$SESSION['memberid'] = $row['memberid'];
$SESSION['first_name'] = $row['first_name'];
$SESSION['last_name'] = $row['last_name'];
$SESSION['email'] = $row['email'];
$SESSION['phone1'] = $row['phone1'];
$SESSION['phone2'] = $row['phone2'];
$SESSION['username'] = $row['username'];
$_SESSION['password'] = $row['password'];
setcookie('member', 'member', time()+24360060);
$login_time = mysql_query("UPDATE member SET last_login=now() where memberid='{$row['memberid']}'");
}
header("Location: http://www.bridgemilltennis.com/members/secure/member-area-main.php");
}
else
{
$SESSION["status"] = "Not logged";
$SESSION['username'] = Guest;
header("Location: http://www.bridgemilltennis.com/members/secure/login_form.php");
exit;
}
break;
}
?>