dpwh11290
2015-08-20 06:34
浏览 65

PHP会话在移动浏览器上销毁太快

I have the following issue. I am building a PHP + jQuery mobile website and I want to maintain the PHP session. The problem here is that when I close the browser App (Samsung Galaxy S4/S5 or Google Chrome on Android) and I leave the phone for say, ten minutes, and then reopen the browser, the whole session appears to be destroyed and I have to log in again.

I tried to increase the cookie lifetime like this:

ini_set('session.cookie_lifetime', 60 * 60 * 24);
ini_set('session.gc-maxlifetime', 60 * 60 * 24);
session_start();

But this does not solve it. I think it is because the browser app purges the session data after some time of inactivity.

Note that I do not want to use "remember me" functionality, I just want to use the PHP session ID.

What would be the correct way to solve this? I have looked at local storage but it seems strange the browser App purges the entire session and I am looking for the simplest solution.

图片转代码服务由CSDN问答提供 功能建议

我有以下问题。 我正在构建一个PHP + jQuery移动网站,我想维护PHP会话。 这里的问题是,当我关闭浏览器应用程序(Android上的三星Galaxy S4 / S5或谷歌浏览器)并且我离开手机说十分钟,然后重新打开浏览器时,整个会话似乎被破坏了我 必须再次登录。

我试图像这样增加cookie的生命周期:

  ini_set('session.cookie_lifetime',60  * 60 * 24); 
ini_set('session.gc-maxlifetime',60 * 60 * 24); 
session_start(); 
   
 
 

但这不是 解决这个问题。 我认为这是因为浏览器应用程序在一段时间不活动后清除会话数据。

请注意,我不想使用“记住我”功能,我只想使用PHP 会话ID。

解决这个问题的正确方法是什么? 我查看了本地存储,但浏览器App清除整个会话似乎很奇怪,我正在寻找最简单的解决方案。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • duanfei1987 2015-10-16 12:56
    最佳回答

    I fixed it (after a lot of trying out) using the php.ini setting

    session.gc_maxlifetime = 3600
    

    After doing this, the mobile browser kept the session alive. Even if I put my phone away for a longer period.

    Apparently setting the maxlifetime does not work if done through a script.

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题