Click to See Complete Forum and Search --> : Cookie Problem


hbradshaw
05-02-2005, 12:45 PM
Hello:

I have a login script in which I want to set a cookie. A cookie should be set only if a user checks the box, Remember Me.

When I run my script, I'm receiving a blank page. I tried placing the code in different places within the script and the result is always the same.

Can someone take a look at my script and help me set my cookie properly?

Thank you very much.

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'];

if ($_POST[remember] == "Yes")
{
setcookie("username", $_SESSION['username'], time()+(60*60*24), ".http://www.bridgemilltennis.com";
setcookie("password", $_SESSION['password'], time()+(60*60*24), ".http://www.bridgemilltennis.com";
}

$login_time = mysql_query("UPDATE member SET last_login=now() where memberid='{$row['memberid']}'");

}
header("Location: http://www.bridgemilltennis.com/mem...r-area-main.php");
}
else
{
$_SESSION["status"] = "Not logged";
$_SESSION['username'] = Guest;
header("Location: http://www.bridgemilltennis.com/mem.../login_form.php");
exit;
}
break;
}
?>

Genixdeae
05-02-2005, 03:51 PM
the only thing i can think of is on these two lines:

setcookie("username", $_SESSION['username'], time()+(60*60*24), ".http://www.bridgemilltennis.com";
setcookie("password", $_SESSION['password'], time()+(60*60*24), ".http://www.bridgemilltennis.com";

you have ".http:blahblah";

what it should be is either "http://blahblah"; or ".http://blahblah."; not sure which you are tring to do or which would be appropriate

hbradshaw
05-02-2005, 04:01 PM
Hi,

I tried your suggestion by fixing the domain and it still isn't working.

Genixdeae
05-02-2005, 04:21 PM
try changing the redirect script with the html version
<meta http-equiv="refresh" content="1;pagetogoto">see if that works

hbradshaw
05-03-2005, 05:26 AM
Hi,

I was able to get the setting of the cookie to work.

Here's what I want to do and I can't get this to work. On the login page, a user can check a box so that the next time they login they will be remembered. In the form, I have: <input type="checkbox" name="remember" value="Yes">.

In theory, 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()+24*3600*60);
}

How could I modify my script to make the above statement to work? Should I include a field in my database table that will flag who wants to or not wants to be remembered and then set the cookie? I'm not sure. The code on the bottom doesn't include the above statement because no matter where I stick it, it won't work.

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()+24*3600*60);



$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;
}
?>