note 30136 added to function.setcookie
| From: | oz at austdesign dot co dot uk | Date: | Fri, 07 Mar 2003 11:25:48 +0000 |
| Subject: | note 30136 added to function.setcookie | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44977@lists.php.net to get a copy of this message | ||
I have had a similair problem with a login script using cookies on Safari on MacOS X and IE6 on
Windows XP
The original script looked like this:
----Code-----
#Encrypt Password
$password = md5($password);
if(authLogIn($username, $password)){
setcookie ('user', $username,time()+3600);
setcookie ('password', $password,time()+3600);
header ("Location: adminhome.php");
exit;
}else{
header ("Location: index.php");
exit;
}
------------------
I changed the setcookie calls to be a complete cookie and only the password was written.
I then figured out that the two browsers do not except cookies that are written directly from the
form that submitted it.
The password was encrypted so the value was different to what was on the form.
the following code is the final working version with a work around to get the username to be written
to a cookie:
-----code-----
#Encrypt Password
$password = md5($password);
$user = $username;
if(authLogIn($username, $password)){
setcookie ('user', $user,time()+3600,
'/','www.siteaddress.co.uk');
setcookie ('password', $password,time()+3600,
'/','www.siteaddress.co.uk');
header ("Location: adminhome.php");
exit;
}else{
header ("Location: index.php");
exit;
}
----------------
--
http://www.php.net/manual/en/function.setcookie.php
http://master.php.net/manage/user-notes.php?action=edit+30136
http://master.php.net/manage/user-notes.php?action=delete+30136
http://master.php.net/manage/user-notes.php?action=reject+30136