Display total online users in web page

Here, how you can display total number of online user in your webpage you want. Just include file name, which I have given file name as online-user.php here. You need to include this file on any php page you want to display total users online.

I have developed this php script to implement on my own webpage.
See this, I have implement this on https://www.ashesh.com.np/nepali-date-converter.php

    Example for how to include online-user.php in web page.
    <?php include 'path/online-user.php'; ?>

online-user.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
$rip = $_SERVER['REMOTE_ADDR'];
$sd  = time();
$count = 1;<!--more-->
 
$file1 = 'online-user-ashesh/ip.txt';
$lines = file($file1);
$line2 = "";
 
foreach ($lines as $line_num => $line)
	{
		//echo $line."<br />";
		$fp = strpos($line,'****');
		$nam = substr($line,0,$fp);
		$sp = strpos($line,'++++');
		$val = substr($line,$fp+4,$sp-($fp+4));
		$diff = $sd-$val;
		if($diff < 900 && $nam != $rip)
			{
			 $count = $count+1;
			 $line2 = $line2.$line;
			 //echo $line2;
			}
	}
 
$my = $rip."****".$sd."++++\n";
$open1 = fopen($file1, 'w');
fwrite($open1,"$line2");
fwrite($open1,"$my");
fclose($open1);
 
echo "<table width=136 height=20 bgcolor=#ffffff style=\"border: 0px green solid;\"><tr><td align=left valign=top>";
echo "<span style=\"font-family: verdana,arial,helvetica; font-size: 9px;\">";
//echo "<a style=\"text-decoration: none; background-color: ; color: #ddccdd;\" href=\"http://www.ashesh.net.np\">A</a></span></td><td align=center>";
echo "<span style=\"font-family: verdana,arial,helvetica; font-size: 11px; font-weight: bold; color: #aaccaa;\">";
echo "Total users online <font color=red>$count</font></span><br />";
echo "</td></tr></table>";
?>

And you need to create empty text file called ip.txt as described in online-user.php code.

You can download here too


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.