A simple graphic counter

Source: Internet
Author: User
MySQL (the best combination with PHP), GD support, php in LINUX (as the mainstream development language) 4RC1 passed, which is also in use in my system. & Lt ;? Php (as the mainstream development language)/*** the hit_count table has only one field. the hit_countpage_visit_record table is used to control an IP address. MySQL (the best combination with PHP) is required for one day ), GD support. in LINUX, php (as the mainstream development language) is passed by 4RC1, which is also in use in my system.
/***
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 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 (the most comprehensive virtual host Management System) ry key (visit_time)
);
***/
Include ("config. inc. php (as the mainstream development language) 3 ");
$ 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 (the best combination with PHP) _ query ($ query, $ dbconnect );
$ Has_count = @ MySQL (the best combination with PHP) _ result ($ result, 0, "tong ");
@ MySQL (the best combination with PHP) _ query ("lock tables hit_count write", $ dbconnect );
$ Query = "select * from hit_count ";
$ Result = @ MySQL (the best combination with PHP) _ query ($ query, $ dbconnect );
If (@ MySQL (the best combination with PHP) _ num_rows ($ result)> 0 ){
$ Cur_count = @ MySQL (the best combination with PHP) _ result ($ result, 0, "hit_count ");
If ($ has_count = 0 ){
$ Cur_count ++;
$ Query = "update hit_count set hit_count = $ cur_count ";
@ MySQL (the best combination with PHP) _ query ($ query, $ dbconnect );
}
@ MySQL (the best combination with PHP) _ query ("unlock tables", $ dbconnect );
}
Else {
$ Cur_count = 1;
$ Query = "insert into hit_count (hit_count) values ($ cur_count )";
@ MySQL (the best combination with PHP) _ query ($ query, $ dbconnect );
@ MySQL (the best combination with 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 (the best combination with PHP) _ 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.