2013-07-06 12:50
浏览 66

extent codeigniter会话到期

I have $config['sess_expiration'] = 7200; on my config.php file, Which means that session last in 2 Hours.

By default the session is created up on user LOGIN. Now i want to last session based on User IDLE state.

So when user is active on page i need to renew the session.


A POLL to server on every 2 minutes through ajax with current user status , IDLE or ACTIVE

if the status is ACTIVE then i want to extent/renew/update the session timeout for another 2 hours from the ajax call.

Infact IF the status is IDLE i will run a timer on web page and before it reaches its timeout (2 hours) i need to display a warning to user ==>

"Your Current session is about to expire. Do you want to renew session ?"

If user clicks YES then i want to extent the session for another 2 hours,else i will send an LOG OUT command.

So the Question is : How i renew/update/extent the session timeout programically ?

Also is there any other better solutions available.

I am using PHP 5 , Codeigniter 2.x , Bitauth( User Authentication ).


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtx3006 2013-07-06 14:58

    Simply you can use the $config['sess_time_to_update'] = 30; //seconds which will update the session timeout if user is idle and session expiration time is over i.e $config['sess_expiration'] = 7200; and then user hits any link it will automatically logged out because CI check the session on each request that whether session expiration time is over or not of exceeds the expiration time then your session is destroyed . If user hits any request after one hour then your sess_time_to_update updates the sess_expiration lets say from now to two hours. By default, CI creates a new session id in a defined interval $config['sess_time_to_update'] = 30; i.e after every 30 seconds new session id will be created

    For a deep closely look you can see the Session.php in libraries sess_update() is the function which updates the session so you have a good idea what CI does if you are not using the database session then CI stores the information in cookie else it stores the data in the ci_sessions table

    点赞 打赏 评论

相关推荐 更多相似问题