A simple graphical counter _php tutorial

Source: Internet
Author: User
Need MySQL (and PHP collocation of the best combination), GD support, Linux under PHP (as the current mainstream development language) 4RC1 through, which is what I do in the system is in use.
/***
Hit_count table only one field Hit_count
The Page_visit_record table is used to control an IP within one day only to produce a counter bounce
CREATE TABLE Page_visit_record (
Visit_time datetime DEFAULT 0000-00-00 00:00:00 not NULL,
Remote_addr Char (a) is not NULL,
Visit_page char () not NULL,
KEY visit_time (Visit_time, Visit_page),
Prima (the most complete virtual host management System) RY KEY (visit_time)
);
***/
Include ("config.inc.php (as current 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 of PHP collocation) _query ($query, $dbconnect);
$has _count= @MySQL (the best combination of PHP collocation) _result ($result, 0, "Tong");
@MySQL (the best combination of PHP collocation) _query ("Lock tables Hit_count write", $dbconnect);
$query = "SELECT * from Hit_count";
$result = @MySQL (the best combination of PHP collocation) _query ($query, $dbconnect);
if (@MySQL (the best combination of PHP collocation) _num_rows ($result) >0) {
$cur _count= @MySQL (the best combination of PHP collocation) _result ($result, 0, "Hit_count");
if ($has _count==0) {
$cur _count++;
$query = "Update hit_count set hit_count= $cur _count";
@MySQL (the best combination of PHP collocation) _query ($query, $dbconnect);
}
@MySQL (the best combination of PHP collocation) _query ("Unlock Tables", $dbconnect);
}
else{
$cur _count=1;
$query = "INSERT into Hit_count (Hit_count) VALUES ($cur _count)";
@MySQL (the best combination of PHP collocation) _query ($query, $dbconnect);
@MySQL (the best combination of PHP collocation) _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 of PHP collocation) _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, Wu, $blue);
Imagestring ($im, 2, 4, 1, $cur _count, $yellow);
Imagestring ($im, 2, 4, 1, $cur _count, $yellow);
Imagegif ($im);
Imagedestroy ($im);

?>


http://www.bkjia.com/PHPjc/509048.html www.bkjia.com true http://www.bkjia.com/PHPjc/509048.html techarticle need MySQL (and PHP collocation of the best combination), GD support, Linux under PHP (as the current mainstream development language) 4RC1 through, this is what I do in the system is used. PHP (as of now ...

  • Related Article

    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.