douguizhuang8276 2016-05-04 13:02
浏览 18
已采纳

如何停止销毁会话

When i close windows tab, session was dead! how can i stop that ?

i use this :

session_start(['cookie_lifetime' => 86400,]);

but when user close tab or move to another page session was dead !

example :
i'm in page => "home"
when i try to go this url "example.com/users"
the session was dead.
• please note this , this problem is just in my website, i can use that ( users page ) in "localhost". but i never can't close browser ( in both (localhost/website) ,
i guess if session will alive for long time ( example 1 day ) , the problem could solved.

thanks.

  • 写回答

1条回答 默认 最新

  • duanbi2760 2016-05-04 13:12
    关注

    a session stays active as long as the browser is active, when it closes the session closes as well. If you want to stop this from happening i recommend you to create a cookie instead. Read all about it here

    cookie example from W3schools on how to create a cookie:

    <?php
    $cookie_name = "user";
    $cookie_value = "John Doe";
    setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");   //    86400 = 1 day
    ?>
    <html>
    <body>
    
    <?php
      if(!isset($_COOKIE[$cookie_name])) {
         echo "Cookie named '" . $cookie_name . "' is not set!";
      } else {
        echo "Cookie '" . $cookie_name . "' is set!<br>";
        echo "Value is: " . $_COOKIE[$cookie_name];
     }
    ?>
    
    </body>
    </html> 
    

    AND the way you are trying to use a session is wrong!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重
  • ¥15 vite打包后,页面出现h.createElement is not a function,但本地运行正常