I’m using CodeIgniter 2.1
I use CodeIgniter’s session to handle whether a user logged in or not. And it works well. I’m storing the sessions to a database. here are a few of my session variables:
$config['sess_expiration'] = 3600;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'user_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = FALSE;
$config['sess_time_to_update'] = 15;
I’m using such a low sess_time_to_update increment because I needed a way to monitor whether a user has closed or navigated away from the page. Since CodeIgniter updates the last_activity column at every update (15 seconds) -To check for idleness I make a query like below (I know it’s not correct language/syntax):
if last_activity < (current_time - 25s)then I know that a user has probably left the page.
The concept works good but I’m wondering if there are any unseen problems with updating the session table so frequently??
Thanks!
if last_activity < (current_time - 25s)only means that no requests were made in the last 25 seconds, not necessarily that the user has left.The last activity won’t actually update every 15 seconds unless the user is making a request every 15 seconds. For instance, if I open a page and read it for five minutes, the last activity won’t update until the next request.
Just the little bit of overhead of updating the session table and refreshing the cookie. 15 seconds is a very small time frame, but it should be fine if that’s what you really need.