简单的图形计数器需要MYSQL,GD的支持
2007-11-11 16:12:47 来源:WEB开发网
<?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),
Prima(最完善的虚拟主机管理系统)RY 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(和PHP搭配之最佳组合)_query($query,$dbconnect);
$has_count=@MySQL(和PHP搭配之最佳组合)_result($result,0,"tong");
@MySQL(和PHP搭配之最佳组合)_query("lock tables hit_count write",$dbconnect);
$query="select * from hit_count";
$result=@MySQL(和PHP搭配之最佳组合)_query($query,$dbconnect);
if(@MySQL(和PHP搭配之最佳组合)_num_rows($result)>0){
$cur_count=@MySQL(和PHP搭配之最佳组合)_result($result,0,"hit_count");
if($has_count==0){
$cur_count++;
$query="update hit_count set hit_count='$cur_count'";
@MySQL(和PHP搭配之最佳组合)_query($query,$dbconnect);
}
@MySQL(和PHP搭配之最佳组合)_query("unlock tables",$dbconnect);
}
else{
$cur_count=1;
$query="insert into hit_count (hit_count) values ('$cur_count')";
@MySQL(和PHP搭配之最佳组合)_query($query,$dbconnect);
@MySQL(和PHP搭配之最佳组合)_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(和PHP搭配之最佳组合)_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);
?>