PHP Classes

File: info.txt

Recommend this page to a friend!
  Classes of bmpc   UsersOnline   info.txt   Download  
File: info.txt
Role: Documentation
Content type: text/plain
Description: Information and algorithm description
Class: UsersOnline
This class calculates the number of users "online"
Author: By
Last change: Added information about the db_log method.
Date: 21 years ago
Size: 1,683 bytes
 

Contents

Class file image Download
bmpc@netcabo.pt This class was written to support multiple databases with a database wrapper module. I converted it for MySQL in order to be published, without the calls to the wrapping functions. To use it, you'll need to create an instance of the "users_online" class, like $o_user = new users_online ( $REMOTE_ADDR ); The $REMOTE_ADDR contains the IP address of the user. Then, the "main" method must be called. This method calls the necessary methods for the algorithm to work properly. The class contains a method that executes an SQL query to the database inserting the "curret" timestamp as well as the number of users counted. Use this carefully because lots of users at the same time will equal lots of insert queries against the database. If you don't need this kind of logs, just don't call it (or control the calls). Refer to the example file for sample usage. Note: The example file includes a if/elseif/else group that checks if the user is behind a proxy. This helps to get a bit more acuratte as two users behind the same proxy get counted as 2 (without the check, only 1 is return), assuming that the proxy server sends one of the variables. If you don't want to use this check, just take the if/elseif/else group out. --------- Algorithm --------- This is a timeout approach that allows us to have a count of the number of users on a website at a given time. It's not 100% accuratte. Description: (start) (log users ip) (check the database for the user's ip) (if the ip exists) (update the timestamp) (if the ip does not exist) (insert a new record) (delete all records that have timeouted) (end)