dqmq0654 2014-03-11 21:58
浏览 48

如果PHP会话在30分钟后过期而没有关闭浏览器吗?

i have a comments system with an option for a user to 'report' a comment.

When clicking report the comment is simply added into a DB table.

To stop any spamming, i set a session on success.

This was aimed to only allow the user to report a comment every 24 mins.

My question is, should a session expire by itself without the need to close the browser?

Currently the session always exists unless the browser is closed.

I have checked phpinfo() and the lifetime is set to the normal 1440.

Or do i have to perhaps set the value of a session to the current time, and then check the value of the session against the current time when reporting a comment?

Thanks!

  • 写回答

1条回答 默认 最新

  • dongmingxiang0312 2015-04-16 10:42
    关注
    if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) {
        // last request was more than 30 minutes ago
        session_unset();     // unset $_SESSION variable for the run-time 
        session_destroy();   // destroy session data in storage
    }
    $_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp
    

    this will just clear the session

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么