This article mainly describes how to use the MySQL database and GD to support simple graphic counters, I have seen the following articles from a reputable website. I believe the following articles will be helpful to many people.
<? Php
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 ),
- Prima (the most comprehensive virtual host Management System) 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 (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 );
- ?>
The above content is an introduction to the support of MySQL and GD for simple graphic counters. I hope you will have some gains.