Simple graphical counters require MYSQL and GD support _ MySQL

Source: Internet
Author: User
Simple graphic counters require MYSQL and GD support /***
Only one hit_count field in the hit_count table
The page_visit_record table is used to control one IP address to generate only one counter in a day.
Create table page_visit_record (


Visit_time datetime DEFAULT '2017-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 );
$ Blue = ImageColorAllocate ($ im, 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 );

?>

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.