dscbxou1900343 2012-04-02 03:25
浏览 102

setcookie()不在Internet Explorer或safari中工作

I had the following code:

setcookie('username', $email, false, 'affiliates/', 'www.mydomain.com');

It wasn't working in IE or Safari. Then I changed it to:

setcookie('username', $email, time()+60*60*24, 'affiliates/', 'www.mydomain.com');

And it started working. Now, 2 days later, it doesn't work again. I don't think I changed anything. The setting of the cookie is being checked in another file, with this code:

if( isset($_COOKIE['username']) ) {
    ...
}
else {
    print( "<meta HTTP-EQUIV='REFRESH' content='0; url=index.html'>" );
    exit();
}

It always redirects to index.html (in Safari and IE). Any ideas why this would cease to work? (I've made sure cookies are enabled in both browsers).

One thing I did during the time it stopped working was test the site running on localhost. I changed the code to:

setcookie('username', $email, time()+60*60*24, 'affiliates/', null);

But only for the localhost version.

  • 写回答

1条回答 默认 最新

  • doumaqing6652 2012-04-02 04:03
    关注

    Are you sure you have setcookie before all the other output? Headers can't be set after any like text or html. Maybe you need to remove any space above your

    Also, the cookie must be set and used from the same domain and path.

    评论

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线边框
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题