This little PHP snippet is used to set a cookie that lets me determine whether or not a user is logged in. For some reason, after I use the javascript to redirect, none of my cookies are set any more. Any reason why this would be happening?
I may not be giving you enough info so let me know if so.
...some database queries...
<?php
$expire=time()+(7 * 24 * 60 * 60);
$row = mysql_fetch_array($query);
$email = $row['email'];
$userinfo['name'] = $name;
$userinfo['email'] = $email;
$userinfo = serialize($userinfo);
setcookie("user", $userinfo, $expire);
echo '<script type="text/javascript">
window.location = "../index.php";
</script>';
?>
Function setcookie returns true or false, depending on whether cookie was set successfully. You could try this to test:
If this returns false, then Kumar is right. Otherwise there has to be some other reason.
EDIT setcookie can be called with more parameters, like this:
Notice the path and domain values. I have had problems in the past with two different pages not find each other’s cookies because of different paths/domains.
I noticed that You redirect to “../index.php”. Try redirecting to “index.php” and see if the cookies exist there. If yes, then You should use a common “path” variable to set cookies.
From http://www.php.net/setcookie about “path” variable: