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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.