douhoulei4706 2016-01-11 23:18
浏览 40
已采纳

cookie问题cookie无法正常运行

I am having serious cookie issues. if I login without using remember me, everything is fine.

If I check remember me, it lets me login but if I close the browser and open it back up it wont auto login it just says page cannot be displayed like its a corrupt cookie.

the only way to make it work again is to delete the cookie

Here is my set function:

if ($remember == "on") {                

             setcookie('email', $email, time() + 86400);

            }

Here is my logout function:

session_destroy();

if(isset($_COOKIE['email'])) {
    unset($_COOKIE['email']);

    setcookie('email', '', time() - 86400);
}

redirect("index.php");

Also, when I look at the cookie file in explorer browser, it looks like this:

email
me%40mymail.net
localhost/mysite/account/
17408
78850176
30494094
3665530565
30493892

So what happens is, I have to delete the cookie to show the login page again.

  • 写回答

1条回答 默认 最新

  • doupin1073 2016-01-12 00:47
    关注

    OK so I figured out the issue... for some reason it had to do with the directories

    to set the cookie I changed this

    if ($remember == "on") {                
    
                 setcookie('email', $email, time() + 86400);
    
                }
    

    to this

    if ($remember == "on") {                
    
                 setcookie("email", $email, time() + 86400,'/');
                }
    

    and I changed this

    session_destroy();
    
    if(isset($_COOKIE['email'])) {
        unset($_COOKIE['email']);
    
        setcookie('email', '', time() - 86400);
    }
    
    redirect("index.php");
    

    to this

    session_destroy();
    
    if(isset($_COOKIE['email'])){
    
        unset($_COOKIE['email']);
    
        setcookie("email", '', time() + 86400,'/');
    
    }
    
    redirect("index.php");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置