hi friends... i want to have a php script using that i can check how many visitors are browsing my site? like DP Currently Active Users... help me if anybody can... thanks
It is really easy to do. First you need a table in your database for visitors. You will need fields for ip addresses and timestamps. function logVisitor(){ $wait=300; // how long before the user is offline, in seconds $offline=time()-$wait; $sql="DELETE FROM visitors WHERE timestamp<'$offline'"; //Delete the rows for offline visitors $query=mysql_query($sql); $ip=$_SERVER['REMOTE_ADDR']; $lastAction=time(); $sql="SELECT * FROM visitors WHERE ip='ip'"; $query=mysql_query($sql); $ipCheck=mysql_num_rows($query); if($ipCheck==0){ $sql="INSERT INTO visitors (ip, timestamp) VALUES ('$ip', '$lastAction')"; $query=mysql_query($sql); }else{ $sql="UPDATE visitors SET timestamp='$lastAction' WHERE ip='$ip'"; $query=mysql_query($sql); }// end ipCheck }//end logVisitor function function numOnline(){ $sql="SELECT * FROM visitors"; $query=mysql_query($sql); $numOnline=mysql_num_rows($query); return $numOnline; }//end numOnline function PHP: Basically it logs each visitor's last action, to determine how many are online. Edit $wait to however long you think it should be. You will run the function logVisitor() on each page. And numOnline() when you want to know how many is online. The same can be used to determine what users are online if you have a membership script. Simply add a lastAction field to the members table to determine who is online.
That is a nice method, but if you have a bigger website with several 1000 users online at the same time and for each click they make, you update your MySQL Server on multiple rows, your Server will go down sooner or later. But for a basic normal website its very nice script.
You could try something like $activeUsers = count(glob(session_save_path().'/sess*')); PHP: Works only if session.save_path is set in php.ini, defaults to '/tmp'. Of course, it has it's downsides, but it should work 99% of the time. Read about PHP sessions if you are unsure how it works.