将 cookie 设置为文件夹内页面的整个域
我是饼干之类的初学者。
我需要从诸如 mydomain.com/folder/page.php
之类的文件夹内的页面为整个域设置 cookie。我之前必须这样做,然后我重定向到另一个设置 cookie 的页面 mydomain.com/another.php
。现在的问题是,由于某些数据来自表单和其他内容,我不应该重定向页面,那么我该怎么做呢?
setcookie("name", $name, time()+31536000);
只会为 folder
内的页面设置 cookie,我尝试了 setcookie("name ", $name, time()+31536000,'/','mydomain.com');
但它不起作用。
I'm a begginer in cookies and stuff like that.
I need to set a cookie to the entire domain from a page inside a folder like mydomain.com/folder/page.php
. I had to do this before and I got it done redirecting to another page mydomain.com/another.php
which set the cookies. The thing is now I should not redirect the page because of some data coming from a form and other things, so how could I do this?
setcookie("name", $name, time()+31536000);
will set the cookies only for the pages inside folder
and I tried setcookie("name", $name, time()+31536000,'/','mydomain.com');
but it didn't worked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此代码绝对有效:
您应该注意
mydomain.com
与www.mydomain.com
或sub.mydomain.com
不同。除此之外,请注意
$value
的值应该是一个字符串。This code definitely works:
You should take note that
mydomain.com
is different fromwww.mydomain.com
orsub.mydomain.com
.Other than this, take note that the value of
$value
should be a string.@SPL_Splinter:确保您在任何输出之前设置cookie。因此,例如:
更新
来自 http://php.net /manual/en/function.setcookie.php
@SPL_Splinter: Make sure you're setting the cookie prior to any output. So, for example:
Update
From http://php.net/manual/en/function.setcookie.php