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/* 本文件为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);
10 fclose($fp);
11 }
12else{
13 $fp=fopen("$countfile","rw+");
14 $num=fread($fp,8);
15 $num++;
16 rewind($fp);
17 fputs($fp,$num,8);
18 fclose($fp);
19 }
20
21/*如果不用图片显示数字,请将以下直到 ?> 之前的部分,改为 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 "您是第";
require("count/count.php");
echo "位访客";
?>
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.