setting PHP cookies
Posted: Wed Dec 24, 2003 11:39 pm
Alright. So I've been developing this site and the authentication code sets a cookie. Easy enough. Anyway, the cookie works perfectly fine on my development server, but when transfered to another, separately-owned server, the cookie just doesn't set. The script is getting to the if statement that has the setcookie() function in it. Identical scripts on both servers. Here is the code:
function admin_login($db)
{
//attempt to login. returns false if invalid and true if correct.
$query = "SELECT * FROM users WHERE username = '".$_POST['username']."'";
$result = mysql_query($query, $db);
$row = mysql_fetch_array($result);
if ($row['password'] == (encrypt($_POST['password']))) {
setcookie( "auth", "1", time()-24*60, "/");
list_admin($db,'');
} else {
setcookie( "auth", "NULL", time()-24*60, "/");
login_check($db);
}
}
Remember that this code works fine on one server and not the other. I really doubt that it's a code problem. Is there something that has to be configured on the server in order to set cookies via PHP? Any advice would be very much appreciated.
Thanks. Bryce.
function admin_login($db)
{
//attempt to login. returns false if invalid and true if correct.
$query = "SELECT * FROM users WHERE username = '".$_POST['username']."'";
$result = mysql_query($query, $db);
$row = mysql_fetch_array($result);
if ($row['password'] == (encrypt($_POST['password']))) {
setcookie( "auth", "1", time()-24*60, "/");
list_admin($db,'');
} else {
setcookie( "auth", "NULL", time()-24*60, "/");
login_check($db);
}
}
Remember that this code works fine on one server and not the other. I really doubt that it's a code problem. Is there something that has to be configured on the server in order to set cookies via PHP? Any advice would be very much appreciated.
Thanks. Bryce.