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 基于52单片机的酒精浓度检测系统加继电器和sim800
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等