首页 > 开发 > PHP > 正文

改进的IP计数器

2024-05-04 23:01:22
字体:
来源:转载
供稿:网友
<?  
//require (’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;  
    }  
}  
$[email protected]_connect("localhost","kong","kong");  
mysql_select_db("mywebdb");
$ip=$remote_addr;  
$current=getdate(time());  
$day=$current["mday"];  
$query="select * from addcount where day=/"$day/"";
$[email protected]_query($query);
if(!$[email protected]_num_rows($result))
    $num=1;
while($[email protected]_fetch_row($result))
{  
    if (strcmp($ip,$row[1])==0)  
    {  
        $i=1;
        $id=$row[0];
        $click=$row[3]+1;
        $up="update addcount set click_count=click_count+1 where id=$id";  
        $[email protected]_query($up);
//        break;
    }  
    $total+=$row[3];
}  
$total++;
if(!$i){
    $query1="insert into addcount (ip,day,click_count )values ('$ip','$day',1)";  
    mysql_db_query("mywebdb",$query1,$link);  
    $click=1;
}
echo "<html><head><title>计数器</title></head>";
    echo "你是第" .$num."访问者<br>";
    echo "今天你第".$click."次点击<br>";
    echo "今天总点击".$total."次<br>";

/*
表:  
addcount  
create table addcount (
   id int(6) default '0' not null auto_increment,
   ip char(20) not null,
   day int(2) not null,
   click_count int(3) not null,
   primary key (id)
);
*/
?>  


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表