count表只一个字段hit
分类:威尼斯手机平台

?php /*** hit_count表只一个字段hit_count page_visit_record表是用来控制一个IP一天内只产生一个计数器跳动 CREATE TABLE page_visit_record ( visit_time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, remote_addr char(15) NOT NULL, visit_page char(60) NOT NULL, KEY visit_time (visit_time, visit_page), PRIMARY KEY (visit_time) ); ***/ include(config.inc.php3); $query=select count(*) as tong from page_visit_record where remote_addr='$REMOTE_ADDR' and date_format(visit_time,'%Y-%m-%d')=curdate(); $result=@mysql_query($query,$dbconnect); $has_count=@mysql_result($result,0,tong); @mysql_query(lock tables hit_count write,$dbconnect); $query=select * from hit_count; $result=@mysql_query($query,$dbconnect); if(@mysql_num_rows($result)0){ $cur_count=@mysql_result($result,0,hit_count); if($has_count==0){ $cur_count++; $query=update hit_count set hit_count='$cur_count'; @mysql_query($query,$dbconnect); } @mysql_query(unlock tables,$dbconnect); } else{ $cur_count=1; $query=insert into hit_count (hit_count) values ('$cur_count'); @mysql_query($query,$dbconnect); @mysql_query(unlock tables,$dbconnect); } while(strlen($cur_count)8) $cur_count=0$cur_count; $visit_time=date(Y-m-d H:i:s); $query=insert into page_visit_record (visit_time,remote_addr,visit_page) values ('$visit_time','$REMOTE_ADDR','$page'); @mysql_query($query,$dbconnect); Header(Content-type: image/gif); $im = imagecreate(56,16); $black = ImageColorAllocate($im, 0,0,0); $blue = ImageColorAllocate($im, 0,0,255); $white = ImageColorAllocate($im, 255,255,255); $yellow = ImageColorAllocate($im, 255,255,0); imagerectangle($im, 0, 0, 54, 14, $blue); //imagestring($im, 2, 4, 1, $cur_count, $yellow); imagestring($im, 2, 4, 1, $cur_count, $yellow); ImageGif($im); ImageDestroy($im); ?

<?  
//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;  
    }  
}  
$link=@mysql_connect("localhost","kong","kong");  
mysql_select_db("mywebdb");
$ip=$REMOTE_ADDR;  
$current=getdate(time());  
$day=$current["mday"];  
$query="select * from addcount where day="$day"";
$result=@mysql_query($query);
if(!$num=@mysql_num_rows($result))
    $num=1;
while($row=@mysql_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";  
        $result2=@mysql_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)
);
*/
?>  

本文由威尼斯在线注册平台发布于威尼斯手机平台,转载请注明出处:count表只一个字段hit

上一篇:php 读取 sogourank 与 ChinaRank信息 下一篇:没有了
猜你喜欢
热门排行
精彩图文