Home > Backend Development > PHP Tutorial > 怎么实现不同IP地址的浏览次数统计

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

WBOY
Release: 2016-06-13 11:31:44
Original
1590 people have browsed it

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

<br /><?php<br />// 访客计数器函数<br />function counter() {<br />	!empty($_GET['weburl'])  ||  die('weburl不能为空');<br />	$weburl = $_GET['weburl'];<br /><br />	$file = '/usr/local/apache/htdocs/MyTests/counter.txt';<br />	if (! file_exists($file)) {<br />		$num = 1;<br />		$cf = fopen($file, 'w');<br />		fwrite($cf, $weburl.' '.$num);<br />		fclose($cf);<br />	} else {<br />		$cf = fopen($file, 'rw');<br />		$num = fgets($cf);<br />		$num = substr($num, 15);<br />		fclose($cf);<br /><br />		++$num;<br />		$cf = fopen($file, 'w');<br />		fwrite($cf, $num);<br />		fclose($cf);<br />	}<br />}<br /><br />?><br /><html><br />	<head><br />		<title>访客计数器</title><br />	</head><br />	<body><br />		<center><br />			<h1>欢迎访问</h1><br /><br />			<form action="counter()" name="url-form" method="get"><br />				<div><br />					<input type="text" name="weburl" size="15" /><br />					 <br />					<input type="submit" name="Submit" value="提交" /><br />				</div><br />			</form><br />			<hr /><br />			<font size="7" color="red"><br />				您是第<?php //echo counter() ?>位访客<br />			</font><br />		</center><br />	</body><br /></html><br /><br />
Copy after login





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

这个程序应该如何修改?

存储 PHP HTML 函数 Color
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template