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