Connecting Tech Pros Worldwide Forums | Help | Site Map

cookies not setting on my computer

tolkienarda's Avatar
Needs Regular Fix
 
Join Date: Dec 2006
Posts: 316
#1: Apr 11 '07
hi all
i am having an unusual and frustrating problem. i am trying to set cookies to register a login. to set to cookie i use the following comand.
[PHP]
if (mysql_num_rows($result) == 1)
{
setcookie("user", $username, mktime()+604800);
//echo '<pre>';
//var_dump($_COOKIE);
//echo '</pre>';
header("location: ../index.php");
}
[/PHP]
when i uncomment the vardump my cookie is beign set
output from above when uncommented:
array(1) {
["user"]=>
string(1) "1"
}
but on the index.php page i cannot read the cookie. i don't know if i am doing somthing wrong but here is the code for index.php.

[PHP]
if ($_COOKIE["user"] != 1);
{
//header("location: login.htm");
var_dump($_COOKIE);
}
[/PHP]

and it just displays

array(0) { }

so either the cookie isn't getting set properly of my method of reading it is incorrect.

thanks for help


eric

Reply