The general counter program uses the Execute external program function exec (), but many host spaces (including charges) reject this dangerous operation.
We have to use Fread (), fwrite () and other files to read and write functions, the key is to use which way fopen () open the file. After having tried 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 picture (0.gif,..., 9.gif)
1<?
2/* This document is count\conut.php * *
3
4$countfile = "Count/counter.txt";
5
6if (!file_exists ("$countfile")) {
7 $fp =fopen ("$countfile", "w");
8 $num = 1;
9 fputs ($FP, $num, 8);
Fclose ($FP);
11}
12else{
$FP =fopen ("$countfile", "rw+");
$num =fread ($FP, 8);
$num + +;
Rewind ($FP);
Fputs ($FP, $num, 8);
Fclose ($FP);
19}
20
21/* If you don't want the picture to display the number, change the following until?> to echo "<font color=red>". $num. " </font> ";
22$len_str = strlen ($num);
23for ($i =0; $i < $len _str; $i + +) {
24$numbers_exploded = substr ($num, $i, 1);
25$output_str = $output _str. "26}
27echo $output _str;
28?>
How to use:
For example, create a new test.php outside the Count folder. Other locations Please modify the $countfile path.
Directly require the count.php file (note path) where test.php is to be displayed.
<br>
<?php
echo "You are the first";
Require ("count/count.php");
echo "Guest";
?>
<br>
To emphasize the last question, please set the Counter.txt file to read and write, and under Windows file permissions under Everyone,linux at least 444. Files on the Web or Linux under the file permissions settings to use the FTP software.