Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to obtain information about active users in mysite

Status
Not open for further replies.

DavidPlus

Programmer
Feb 20, 2007
38
NL
Hi all. could any one tell me how i can obtain information about active users in my webpage. I want to be able to track them in almost real time. Could any one tell me how i can do that in php.looking forward for your replies.Thanks
 
You could have a table called say "hits" and then have code on each page which would add an entry to this table whenever they view a certain page. code could be:

Code:
  $ip = getenv("REMOTE_ADDR");
  $date = date("j M y G:ia");
  $page = $_SERVER[PHP_SELF];
  $sql = "INSERT INTO hits VALUES('','$ip','$date','$page')";
  $result = mysql_query($sql) or die(mysql_error());

This assumes a connection to the database has already been made. You will need to make the table with IP, Date and Page fields, plus an ID field as the primary key.

you could also add the username by using creating a session variable at login and inserting that into the database aswell.

You could then have a page that could retrieve information from this each time you refresh although you would want to put some limit on it otherwise it could potentially be a very large output - say limit it to the 10 most recent entries.

Additonally if its a large, multi user site...this way probably isnt very efficient at all and could result in a huge hits table

You would need the code on every page!

'When all else fails.......read the manual'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top