omgRawr Posted July 27, 2009 Share Posted July 27, 2009 How can you monitor with PHP how many users and guests are on a single page? I know that you could query information from the database to determine how many users are online, for example: select username, current_page from users where online = 1 and page = 'news' But, how can you monitor how many guests are online? Do I have to use the same method for guests - add a row to a table containing the guests currently logged on? Would something like this work? create table all_users ( id int not null auto_increment, last_activity datetime not null, ip_address varchar(32) not null, user_agent varchar(255) not null, page varchar(64) not null, referer varchar(255) null, primary key (id) Then if I wanted to check how many guests are viewing a page: select count(distinct ip_address) as views from all_users where page = 'news' And that should work, but there's another problem. How can I delete the row from the database when users leave my website? If there are only guests and there is no logout feature, then how can I delete their "session" (not really a session, just their row in the database). How can I delete their "session" if they just exit out of their browser window instead of pressing a button?Any help would be appreciated, thanks. Link to comment Share on other sites More sharing options...
jeffman Posted July 27, 2009 Share Posted July 27, 2009 Define a timeout length, say 15 minutes (or whatever is appropriate to your content). Every time you update the users/guests database, examine every record. (You're probably doing it anyway to generate the information.) For each record, get the absolute difference between last_activity and the current time. If that difference is greater than the timeout length, remove the record. Link to comment Share on other sites More sharing options...
omgRawr Posted July 27, 2009 Author Share Posted July 27, 2009 Define a timeout length, say 15 minutes (or whatever is appropriate to your content). Every time you update the users/guests database, examine every record. (You're probably doing it anyway to generate the information.) For each record, get the absolute difference between last_activity and the current time. If that difference is greater than the timeout length, remove the record.Perfect! Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.