run just before session expires in codeigniter
I have some method about user statistics to run just before CI session expires.
I am us开发者_StackOverflow社区ing codeigniter database session.
plz give me a pieces of advice.
There's no out of the box way to do this with CodeIgniter. One solution would be to configure sessions not to expire, save a session expiration timestamp in the database, and then handle the session expiration on the server side. In your code you would perform a check to see if the session had expired. If it had you would call your method and remove the session.
Here is a thread from the CodeIgniter forums that explains it.
http://codeigniter.com/forums/viewthread/199727/
you have an approach to what you are trying to do, but it will not excute exactly at the real ticking time when session expire, it will excute when the system checks if the cookie is deleted to create a new session. I believe that it will do 80% of the goal you are seeking. try the following edit in the System/libraries/Session.php:
if ( ! $this->sess_read())
{
//your code here//
$this->sess_create();
}
else
{
$this->sess_update();
}
you'll find the previous piece of code around line 105. good luck.
精彩评论