setcookie 不起作用

发布于 2024-07-24 04:52:58 字数 480 浏览 2 评论 0原文

我有一个名为index.php 的简单文件。 我需要向它传递一个查询字符串,该字符串将存储在永不过期的 cookie 中。 该文件看起来完全像这样:

<?php

if (isset($_GET['referrer_id']))
{
    $querystringWithJunk = $_GET['referrer_id'];
    $querystringArray = explode('/', $querystringWithJunk);

    setcookie("referrer_id", $querystringArray[0], time() + 60*60*24*365*100);
}?>

但是,没有设置 cookie。 Referrer_id 里面的内容是一个简单的整数(在我所做的测试中,它是 1)。 函数 setCoookie 返回 true,一切似乎都工作正常,但没有设置 cookie。 难道我做错了什么?

I have a simple file called index.php. I need to pass it a querystring that will be stored inside a never-expiring cookie. The file looks exactly like this :

<?php

if (isset($_GET['referrer_id']))
{
    $querystringWithJunk = $_GET['referrer_id'];
    $querystringArray = explode('/', $querystringWithJunk);

    setcookie("referrer_id", $querystringArray[0], time() + 60*60*24*365*100);
}?>

However, no cookie is set. What is inside referrer_id is a simple integer (in the tests I made, it's 1). Function setCoookie return true and everything seems to works fine but no cookie is set. Am I doing something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丶视觉 2024-07-31 04:52:59

time比int大,所以我认为result是负数,然后cookie被设置成过去,什么意思,它被删除了。 将时间设置为 3 年而不是 100 年。

Time is bigger than int, so I think result is negative, and then cookie is set into past, what means, it is deleted. Set time to 3 years instead of 100.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文