PHP counter Program: Solve all possible problems _php tutorial

Source: Internet
Author: User
Tags fread
The general counter program uses the Execute external program function exec (), but many host spaces (including charges) reject this dangerous operation.
We had to use Fread (), fwrite () and other file read and write functions, the key is to use the way fopen () open the file. After trying n times, it is proved that the following procedure is feasible and verified on the charge space.

Count Directory
|---count.php
|---counter.txt
|---0~9 digital GIF image (0.gif,..., 9.gif)
/* This file is countconut.php */

$countfile = "Count/counter.txt";

if (!file_exists ("$countfile")) {
$FP =fopen ("$countfile", "w");
$num = 1;
Fputs ($FP, $num, 8);
Fclose ($FP);
}
else{
$FP =fopen ("$countfile", "RW");
$num =fread ($FP, 8);
$num;
Rewind ($FP);
Fputs ($FP, $num, 8);
Fclose ($FP);
}

/* If you do not use the picture to display the numbers, change the following until?> to echo "". $num. ""; Like * *
$len _str = strlen ($num);
for ($i =0; $i < $len _str; $i) {
$numbers _exploded = substr ($num, $i, 1);
$output _str = $output _str. "";
}
echo $output _str;
?>
How to use:
For example, create a new test.php outside the Count folder. Other locations, modify the $countfile path.
Require the count.php file (focus on the path) directly at the place where test.php is to be displayed.


echo "You are the first";
Require ("count/count.php");
echo "Bit visitor";
?>



To emphasize the last issue, set the Counter.txt file to read and write, and the file permissions under Windows Everyone,linux at least 444. Files on the Web or under Linux file permissions are set to use the FTP software.

http://www.bkjia.com/PHPjc/631986.html www.bkjia.com true http://www.bkjia.com/PHPjc/631986.html techarticle The General counter program uses the Execute external program function exec (), but many host spaces (including charges) reject this dangerous operation. We had to use Fread (), fwrite () and other file reading and writing functions ...

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