Home >Backend Development >PHP Tutorial >Use IP addresses to count the number of visitors! The limit is heaven! _PHP Tutorial
require ('common.inc');
$ip=$REMOTE_ADDR;
$current=getdate(time());
$day=$current["mday"] ;
$query="select * from count";
$result=MySQL(The best combination with PHP)_db_query('football',$query,$link);
while($row=MySQL(The best combination with PHP)_fetch_row($result))
{
$num=$row[2];
if ( strcmp($ip,$row[0])==0 && $day==$row[1])
{
$i=1;
}
}
if ( $i<>1)
{
++$num;
echo "You are the" .$num;
echo "Visitor";
$query1="insert into count values ('$ip',$day,$num)";
MySQL(The best combination with PHP)_db_query('football',$query1,$link);
}
else
{
echo "You are the" .$num;
echo "Visitor";
}
?>
common. inc:
$arr_request=array();
if (count($HTTP_GET_VARS))
{
while (list($key,$value)=each($ HTTP_GET_VARS))
{
$arr_request[strtolower($key)]=$value;
}
}
if (count($HTTP_POST_VARS))
{
WHILE (list($key,$value)=each($HTTP_POST_VARS))
{
$arr_request[strtolower($key)]=$value;
}
}
$link= MySQL(The best combination with PHP)_connect("localhost","root","");
?>
The library is:
football
Table:
count
Field: ip->char(20)
day->int(2)
num->int(8)
This program is slightly modified It can be modified to become a multi-user counter, and it cannot be faked!
For personal use only!