A simple graphics counter

Source: Internet
Author: User
<?php
/***
Hit_count table only one field Hit_count
Page_visit_record table is used to control an IP one day and only produce a counter beat
CREATE TABLE Page_visit_record (
Visit_time datetime DEFAULT ' 0000-00-00 00:00:00 ' not NULL,
Remote_addr char (not NULL),
Visit_page char (=) 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, $blue);
Imagestring ($im, 2, 4, 1, $cur _count, $yellow);
Imagestring ($im, 2, 4, 1, $cur _count, $yellow);
Imagegif ($im);
Imagedestroy ($im);
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.