PHP counter Implementation Code _php tips

Source: Internet
Author: User
Copy Code code as follows:

<?php
/* 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 "?>

Copy Code code as follows:

<?php
The following is a simple database based counter that does not add other methods to prevent one person from repeatedly refreshing. For reference 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 "mysql_query ("Update tb_counter set counter= $counter");
Mysql_close ($conn);
?>

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.