我发现了一个非常创新和像样的计数器,它让我把计数器的代码放在主index.php页面上,然后通过我的后端系统查看计数器,然而,尽管它的工作方式,它打破了主页面,因为PHP错误,因为旧的代码;我知道一些PHP,但还不够知道我要修复什么。
计数器教程:counter tutorial link
count.db
0%0%0%0000 00 00%0counter.php:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$file_ip = fopen('counter/ip.db', 'rb');
while (!feof($file_ip)) $line[]=fgets($file_ip,1024);
for ($i=0; $i<(count($line)); $i++) {
list($ip_x) = split("\n",$line[$i]);
if ($ip == $ip_x) {$found = 1;}
}
fclose($file_ip);
if (!($found==1)) {
$file_ip2 = fopen('counter/ip.db', 'ab');
$line = "$ip\n";
fwrite($file_ip2, $line, strlen($line));
$file_count = fopen('counter/count.db', 'rb');
$data = '';
while (!feof($file_count)) $data .= fread($file_count, 4096);
fclose($file_count);
list($today, $yesterday, $total, $date, $days) = split("%", $data);
if ($date == date("Y m d")) $today++;
else {
$yesterday = $today;
$today = 1;
$days++;
$date = date("Y m d");
}
$total++;
$line = "$today%$yesterday%$total%$date%$days";
$file_count2 = fopen('counter/count.db', 'wb');
fwrite($file_count2, $line, strlen($line));
fclose($file_count2);
fclose($file_ip2);
}
?>showcounter.php
<table>
<tr>
<th colspan="2">Unique visitors</th>
</tr>
<tr>
<td><b>Today</b></td>
<td>
<?php
$file_count = fopen('counter/count.db', 'rb');
$data = '';
while (!feof($file_count)) $data .= fread($file_count, 4096);
fclose($file_count);
list($today, $yesterday, $total, $date, $days) = split("%", $data);
echo $today;
?>
</td>
</tr>
<tr>
<td><b>Yesterday</b></td>
<td>
<?php
echo $yesterday;
?>
</td>
</tr>
<tr>
<td><b>Total</b></td>
<td>
<?php
echo $total;
?>
</td>
</tr>
<tr>
<td><b>Daily average</b></td>
<td>
<?php
echo ceil($total/$days);
?>
</td>
</tr>
</table>感谢所有的回复,非常感谢,希望我们能让它再次工作:)
编辑:我的浏览器崩溃了,给你们一些错误信息:P
Warning: fopen(ip.db) [function.fopen]: failed to open stream: No such file or directory in /counter/counter.php on line 4
Warning: feof(): supplied argument is not a valid stream resource in /counter/counter.php on line 5
Warning: fgets(): supplied argument is not a valid stream resource in /counter/counter.php on line 5
Warning: feof(): supplied argument is not a valid stream resource in /counter/counter.php on line 5它显示“没有这样的文件”,但是计数器被上传到/ ip.db /
Contents of the /counter/ folder:
count.db
counter.php
ip.db
index.html
showcounter.phpip和count.db,chmod到666
发布于 2011-09-24 20:10:33
您说您的文件名为countdb.php,但代码中没有一个对该文件名的引用。确保您的文件命名正确。
https://stackoverflow.com/questions/7538899
复制相似问题