yeah, the easiest way is to use pre-made scripts or services offering that. Im using http://whos.amung.us/ in my blog and are very glad with that.
create a blank file and name it online.txt create a file online.php and add the below code to it. Upload to your server and give online.txt write permissions.
Why not just create a session on page load, and assign $_SESSION["user"] to "Guest" or another anonymous name. Then to display Who's Online just count the session array. Haven't tried this method first hand (never had a reason to show this type of data) but I don't see why it wouldn't work. All in all it would be about 3 lines of code.
The easiest way to count online users is to create a new $_SESSION for each user and then count the number of files in your "session.save_path" directory.
Thanks for the script, helped me too Same problem.... how can i solve the problem, i m newbie in php, can anybody give the code where it will not show "0 users online" when i refresh the page means it show always same user untill i leave the page. plz help....
Try this code: Copy the code and put in a file, and include that file on all php files where you want to count and show total users. Make a ip.txt file to store data <?php $file= 'ip.txt'; //file to store data $every=20; //start counting from 0 after these many minutes //no need to edit below $ip = $_SERVER['REMOTE_ADDR']; $a= file_get_contents($file); $a=explode("\n",$a); if(is_numeric($a[0])){ if((time()-$a[0])>($every*60)){ $st= time()."\n".$ip; $fp=fopen($file,'w'); fwrite($fp,$st); fclose($fp); }else{ if(!in_array($ip,$a)){ $st= "\n".$ip; $fp=fopen($file,'a'); fwrite($fp,$st); fclose($fp); } } }else{ $st= time()."\n".$ip; $fp=fopen($file,'w'); fwrite($fp,$st); fclose($fp); } echo '<p>Total users online: '. (sizeof($a)-1). '</p>'; ?> Code (markup): Thanks
It means that "total users online: 50 in last 20 minutes" It's tracking total users online in last 20 minutes, and after 20 minutes it deletes all data and starts new tracking. If you want to track for last 5 minutes, use: $every=5; for the last 1 hour: $every=60; and so on. Thanks
Thanks JEET for ur greater help, JEET could u make me some more help... 1) Problem is to use this script, this script take some times to load it, need more faster script. 2) Can i use it for my business website? 3) Can u help me for shortcut? means i want to use a line script not full script every page. Full script will have in another secured page or secured file.
Write script in a new page say counter.php Then call it on the page where you want to show total online visitor or just include it in your footer... <? include('counter.php') ?>