PHP Counter Implementation Code _php tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:
/ * Simple implementation of recording data using a text file */
$counter = 1;
if (file_exists ("Mycounter.txt")) {
$FP =fopen ("Mycounter.txt", "R");
$counter =fgets ($FP, 9);
$counter + +;
Fclose ($FP);
}
$FP =fopen ("Mycounter.txt", "w");
Fputs ($fp, $counter);
Fclose ($FP);
echo "

You are the first ". $counter." Times to visit this page!

";
?>

Copy CodeThe code is as follows:
//The following is a simple database-based counter that does not add other methods that prevent one person from repeating the refresh. For informational purposes only.
$conn =mysql_connect ("localhost", "root", "abc");
$result =mysql_query ("Use Db_counter");
$re =mysql_query ("SELECT * from Tb_counter");
$result =mysql_fetch_row ($re);
$counter = $result [0];
echo "You are the first {$counter} visitor! ";
$counter +=1;echo "{$counter}";
mysql_query ("Update tb_counter set counter= $counter");
Mysql_close ($conn);
?>

http://www.bkjia.com/PHPjc/327475.html www.bkjia.com true http://www.bkjia.com/PHPjc/327475.html techarticle Copy the code as follows: PHP/* Simple implementation of data logging using text files */$counter =1; if (file_exists ("Mycounter.txt") {$fp =fopen ("Mycounter.txt", "R") ; $counter =fgets ($fp, 9 ...

  • 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.