dongxun6458 2014-07-04 08:07
浏览 58
已采纳

会话超时后,PHP会话变量仍然存在

I'm making a webapp and using session to keep loged in user data. i I set 2 variables $_SESSION["loged_in"] and $_SESSION["user_id"] to know whether the user is connected or not. but when the session reach it's timeout, the variables still exists which distort my logic. how can i solve that ?

  • 写回答

1条回答 默认 最新

  • dreljie602951 2014-07-04 08:43
    关注

    Are you sure that session has reached it's timeout?

    Based on your question, if the session is still exist I think the session has not reached it's timeout. session have a lifetime. session lifetime can you see in a file that name php.ini

    In that file you can found how long session lifetime in the value of var session.gc_maxlifetime. You can set/change session lifetime by following the steps in the following link How to change the session timeout in PHP?

    ====== UPDATE ======

    based on your comment, may be you haven't create code to logout the user if they try to load a page when they've been inactive for too long

    you must "create code to check session time and create code to logout" in every .php file you have.

    if( $_SESSION['last_activity'] < time()-$_SESSION['expire_time'] ) { 
        header('Location: http://yoursite.com/logout.php');
    } 
    else{ 
        $_SESSION['last_activity'] = time(); //this was the moment of last activity.
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效