CodeIgniter: storing sessions in DB, how to know who session came from? -


i'm thinking of storing ci sessions in database can display how many users online, online, etc.

looking @ http://codeigniter.com/user_guide/libraries/sessions.html, right in understanding information stored in user_data column of ci_session table? meaning, maybe store user's id in there?

codeigniter store data in table specify in config file. default, it's ci_session. session information, accessible through $_session instance, serialized , saved in column named user_data. field not able tell whether or not session has expired (or in other words, how many people online).

what instead use last_activity column, timestamp of last time session active. run sql query selects count of session_id last_activity less 2 minutes ago.

select count(`session_id`) `active_user_count` `ci_session` `last_activity` >= date_sub(current_timestamp, interval 2 minute) 

with said, existing session doesn't mean user "signed in". if need check they're signed in, can use like operator add condition where statement checks if user signed in. depend on variable name you're using have @ data , see if can figure out.

for example:

select count(`session_id`) `active_user_count` `ci_session` `last_activity` >= date_sub(current_timestamp, interval 2 minute) , `user_data` '%s:9:"logged_in";b:1;%' 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -