PHP setcookie()不工作 [英] PHP setcookie() not working
问题描述
在一个页面上我有这样的
setcookie('user','value',6000,'/ ,'mydomain.co.uk');
在后续页面上我有
var_dump($ _ COOKIE);
我可以看到所有自动生成的,如 PHPSESSID
但我看不到 user
。
如果我做
echo setcookie用户','价值',6000,'/','mydomain.co.uk');
它返回 true
。所以我不知道为什么我看不到它。 我尝试了很多不同的想法,但没有什么工作。此外,我使用.htaccess通过一个页面重定向所有请求 index.php
不知道这是否做任何事情。
尝试这样:
setcookie('user','value' time()+ 6000,'/','mydomain.co.uk');
expires参数需要是时间戳。 6000
作为时间戳是过去的,因此删除了cookie。
On one page I have something like this
setcookie('user', 'value' ,6000, '/', 'mydomain.co.uk');
On the subsequent page I have
var_dump($_COOKIE);
I can see all the automatically generated ones, like PHPSESSID
but I cannot see user
.
If I do echo setcookie('user', 'value' ,6000, '/', 'mydomain.co.uk');
it returns true
. So I'm not sure why I can't see it.
I have tried a lot of different ideas, but nothing has worked. Also, I have using .htaccess to redirect all requests via one page index.php
not sure if this is doing anything.
Try this:
setcookie('user', 'value' ,time() + 6000, '/', 'mydomain.co.uk');
The expires Parameter needs to be a timestamp. 6000
as a timestamp is in the past and therefore removes the cookie.
这篇关于PHP setcookie()不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!