Rumah >pembangunan bahagian belakang >tutorial php >用IP地址来统计访问人数!以天为间限!_PHP教程
require (’common.inc’);
$ip=$REMOTE_ADDR;
$current=getdate(time());
$day=$current["mday"];
$query="select * from count";
$result=MySQL(和PHP搭配之最佳组合)_db_query(’football’,$query,$link);
while($row=MySQL(和PHP搭配之最佳组合)_fetch_row($result))
{
$num=$row[2];
if (strcmp($ip,$row[0])==0 && $day==$row[1])
{
$i=1;
}
}
if ($i1)
{
++$num;
echo "你是第" .$num;
echo "访问者";
$query1="insert into count values (’$ip’,$day,$num)";
MySQL(和PHP搭配之最佳组合)_db_query(’football’,$query1,$link);
}
else
{
echo "你是第" .$num;
echo "访问者";
}
?>
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(和PHP搭配之最佳组合)_connect("localhost","root","");
?>
库为:
football
表:
count
字段:ip->char(20)
day->int(2)
num->int(8)
这个程序稍加修改就可成为多用户记数器,而且不能作假哟!
仅作个人用!