怎么实现不同IP地址的浏览次数统计

原创
2016-06-13 12:40:12 869浏览

如何实现不同IP地址的浏览次数统计

// 访客计数器函数
function counter() {
!empty($_GET['weburl']) || die('weburl不能为空');
$weburl = $_GET['weburl'];

$file = '/usr/local/apache/htdocs/MyTests/counter.txt';
if (! file_exists($file)) {
$num = 1;
$cf = fopen($file, 'w');
fwrite($cf, $weburl.' '.$num);
fclose($cf);
} else {
$cf = fopen($file, 'rw');
$num = fgets($cf);
$num = substr($num, 15);
fclose($cf);

++$num;
$cf = fopen($file, 'w');
fwrite($cf, $num);
fclose($cf);
}
}

?>


访客计数器



欢迎访问













您是第位访客










我想实现一个输入不同的IP地址并提交后,在“您是第...位访客”中显示相应IP访问了多少次。。。我用一个TXT文件存储IP地址与浏览次数,格式如下:
例:
192.168.0.22 5
192.168.5.44 10
......

这个程序应该如何修改?
存储 PHP HTML 函数 Color