_php Tutorials for simple counters

Source: Internet
Author: User

Simple counter

/*
|| A simple counter
*/
function Get_hitcount ($counter _file)
{
/* Reset counter to zero
So if the counter is not yet in use, the initial value will be 1.
Of course you can set the initial value to 20000来.
*/
$count = 0;
If the store counter file already exists, read the contents
if (file_exists ($counter _file))
{
$FP =fopen ($counter _file, "R");
We only took the top 20, I hope your site is not too popular AH
$count =intval (fgets ($FP, 20));
Since the function fgets () returns a string, we can automatically convert it to an integer by adding a 0 method
Fclose ($FP);
Operation completed on file
}
Increase the value of a single count
$count;
Writes a new count value to a file
$FP =fopen ($counter _file, "w");
Fputs ($fp, $count);
Fclose ($FP);
# returns the Count value
return ($count);
}
?>

http://www.bkjia.com/PHPjc/631904.html www.bkjia.com true http://www.bkjia.com/PHPjc/631904.html techarticle simple counter?/* | | A simple counter */function Get_hitcount ($counter _file) {/* The counter is zeroed so if the counter has not been used, the initial value will be 1 of course you can ...

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