首页 > 数据库 > MySQL > 正文

一个简单的图形计数器,需要MYSQL,GD的支持,LINUX下PHP4RC1通过

2024-07-24 12:56:11
字体:
来源:转载
供稿:网友
<?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()";
$[email protected]_query($query,$dbconnect);
$[email protected]_result($result,0,"tong");
@mysql_query("lock tables hit_count write",$dbconnect);
$query="select * from hit_count";
$[email protected]_query($query,$dbconnect);
if(@mysql_num_rows($result)>0){
    $[email protected]_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);

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