Cookie在服务器上不起作用,但在本地运行良好


Cookie not working on server though working fine in local

我正在尝试获取我在另一个文件中设置的电子邮件cookie的值。设置cookie的代码如下:

setcookie('email', $_SESSION['email'], time()+3600*24*30, 'www.example.com');

在另一个文件中,我试图将这个cookie称为

$email=$_COOKIE["email"];

然而,它似乎并没有将该值设置为$email变量,但当我尝试在其他查询中使用$email的值时,它运行良好。我把我所有的代码都放在这里,以免含糊不清。

`$email=$_COOKIE['email'];`

$result= mysql_query("select firstname from users where email='$email'");

$firstname=mysql_result($result,0);

echo $email;

$result2= mysql_query("select userid from users where email='$email'");

$cus_id=mysql_result($result2,0);

echo $cus_id;

$result3=mysql_query("select count(*) from cart where userid='$cus_id'");

$proInCart=mysql_result($result3,0);

echo $proInCart;

所以$email&cus_id没有打印,但$proInCart运行良好。在这种情况下有人能帮忙吗?还有一件事,它只是在服务器上不起作用,在本地,一切都像一个魅力。

已经完成了。设置cookie时出现问题,因为该文件中已经发送了标头,cookie没有保存。现在完成。:)