dongzhang1987
dongzhang1987
2012-12-05 10:19

PHP - 您是否需要再次设置会话数据以重置生命周期?

已采纳

...or do you only need to start a new session?

I've been given the task of fixing a bug that causes sessions to expire even though the session.gc_maxlifetime is set to 8 hours (It does get set, i've checked).

After going through the code, i noticed that session_start() is called on every load, as predicted, but the login-data sessions are only set when the user logs in.

Do i need to set the user data sessions on every page load for the session-lifetime to reset?

I need the session to be alive for 8 hours, even if the page doesn't reload.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • dongnaosuan5407 dongnaosuan5407 9年前

    You need to set the session variable again.

    One method, use $_SESSION['last_click_time'] = time(); and compare it. If it's outdated, refresh the session variable, log the user back in, etc etc.

    点赞 评论 复制链接分享
  • douhuzhi0907 douhuzhi0907 9年前

    You are probably using the default location for session files and it's a temporary directory shared by all web sites on the server. In that case, the site with shortest session.gc_maxlifetime will probably remove session data from all sites. The reason is that there's no way to determine what site owns what session file.

    You'll need to create a custom directory for sessions and specify it with session.save_path

    点赞 评论 复制链接分享