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.

  • 写回答

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条)

报告相同问题?

悬赏问题

  • ¥15 求指导ADS低噪放设计
  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存