日期:2014-05-17 浏览次数:20485 次
<?php
// 访客计数器函数
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);
}
}
?>
<html>
<head>
<title>访客计数器</title>
</head>
<body>
<center>
<h1>欢迎访问</h1><br />
<form action="counter()" name="url-form" method="get">
<div>
<input type="text" name="weburl" size="15" />
<input type="submit" name="Submit" value="提交" />
</div>
</form>
<hr />
<font size="7" color="red">
您是第<?php //echo counter() ?>位访客
</font>
</center>
</body>
</html>
<?php
// 访客计数器函数
function counter() {
!empty($_GET['weburl'])
------解决方案--------------------
die('weburl不能为空');