Cookie未设置 [英] Cookie does not set

查看:122
本文介绍了Cookie未设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个cookie,不会在远程服务器上设置,工作在本地查找。没有错误消息,var_dump让我为空,回声为空。

 < php 
setcookie('ymp', '14',time()+ 3600);
session_start();
?>

我可以设置一个javascript cookie。



感谢
Gary

p>

在编辑



我有一些意见,我在下面发布,它是一个3个文件的过程。



第一页是设置cookie,如上所述。



第二页我要调试

 < php var_dump($ _ COOKIE ['ymp']); echo'< br /> ;'.$_COOKIE['ymp'];?> 

第3页,再次这一切都在本地工作我有

 <?php 
if($ _ COOKIE ['ymp']!=='14')
{没有你的令人愉快的小糕点.... ....再试一次。);}



我设置了一个js cookie,并更改了代码以反映不同的cookie名称,并且工作正常。



我还将时间重置为+86400,因为两个小时的时间差异到服务器,虽然我不认为这是真的需要。



感谢所有帮助



Gary

解决方案

指定cookie的路径和/或域。尝试这样:

 <?php 
setcookie('ymp','14',time 3600,'/','yourdomain.com')
?>


I have a cookie that will not set on the remote server, works find locally. No error messages, var_dump gets me Null, echo is blank.

<php
 setcookie('ymp','14', time()+3600);
 session_start();
?> 

I can set a javascript cookie fine. The opening tag is line 1 of the page.

Any ideas

Thanks Gary

On Edit

I have some comments I posted below, it is a 3 file process.

Page one is to set the cookie, as above.

Page two I have for debugging

<php var_dump($_COOKIE['ymp']); echo'<br />'.$_COOKIE['ymp'];?>

Page 3, and again this all worked locally I have

 <?php
 if($_COOKIE['ymp']!=='14')
 {die('Sorry, you have not had your delightful little pastry yet.... try again.');}

?>

I set a js cookie, and changed the code to reflect the different cookie name and it worked fine.

I also reset the time to +86400, because of the two hour time difference to the server, though I don't think that is really required.

Thanks for all the help

Gary

解决方案

It could be because you don't specify a path and/or a domain for the cookie. Try this instead:

<?php
    setcookie('ymp','14', time()+3600, '/', 'yourdomain.com')
?>

这篇关于Cookie未设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆