Welcome Guest, Not a member yet? Register   Sign In
How to track Who's Online
#1

[eluser]Unknown[/eluser]
Hi, i have some different type of user and like as pro and learner. I want to track out who is online from those who are pro and who is online from learner. In code igniter how can i do it. I give the user_id in session when it log in.

plz help me

Best Regards
Behestee
#2

[eluser]davidbehler[/eluser]
Actually you can't track in real time who is online and who is not (well...you could do that using javascript but let's say you only want to use php and mysql) but you can track who was online in the last 5 minutes. All you need is a column in your user table of the type timestamp or datetime that you update each time the user logs in/moves on your site.

And then you can use something like this to determine who has been online in the last 5 minutes:
Code:
SELECT * FROm user_table WHERE DATE_ADD(datetime_column, INTERVAL 5 MINUTE) >= NOW();

As far as I know that (or something similar) is how it's done most of the time/how I usually do it.
#3

[eluser]rogierb[/eluser]
Since you have the session and the user_id, it shouldn't be that difficult.

use something like
Code:
select GROUP_CONCAT( user_id ORDER BY user_id DESC SEPARATOR ',' )as user_ids from session_table

To get all the user_ids => $user_ids.

Then do something like
Code:
select role, count(role) from user_table where user_id in ( $user_ids ) group by role

This should leave you with 2 records, one for each role.
#4

[eluser]bd3521[/eluser]
Something like this should also work - assuming you have a userdata set (with db sessions on) for the key "username"

select * from ci_sessions where user_data like '%username%' order by last_activity desc;
Then just extract the username




Theme © iAndrew 2016 - Forum software by © MyBB