<?php
function hit_count()
{
$ip_address = $_SERVER['REMOTE_ADDR'];
$ip_file = file('ip.txt'); //file() function stores each line of that text file in form of an array.
foreach($ip_file as $ip)
{
//echo $ip.', ';
$ip_single = trim($ip); //space is there at the end of each line so you can use trim to remove the white space.
if($ip_address == $ip_single)
{
$found = true;
break;
}else{$found = false;}
}
if($found == true){
echo 'found';
} else {echo 'not found';}
}
?>
错误是:
注意:未定义的变量:在第18行的C:\ xampp \ htdocs \ series \ 72Hit counter \ uniqueHitcounter \ count.php中找到
它在此行if($found == true)
中为true或false,并且在同一函数内定义。
我从一个单独的文件中包含并调用此函数。