PHP counter program: solve all possible problems_PHP tutorial

WBOY
Release: 2016-07-13 10:58:38
Original
1027 people have browsed it

General counter programs use the external program function exec(), but many host spaces (including paid ones) reject this dangerous operation.
We have to use fread(), fwrite() and other file reading and writing functions. The key lies in which method fopen() is used to open the file. After trying N times, it was confirmed that the following procedure is feasible and has been verified in the paid space.

count directory
|---count.php
|---counter.txt
|---Number GIF pictures from 0~9 (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 pictures to display numbers, please change the following part until ?> to something like echo "".$num."";*/
$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. Please modify the $countfile path in other locations.
Directly require the count.php file where test.php is to be displayed (pay attention to the path).


echo "You are No.";
require("count/count.php");
echo "Visitors";
?>



To emphasize the last question, please set the counter.txt file to be readable and writable. The file permissions are everyone under Windows and at least 444 under Linux. To set file permissions on the Internet or under Linux, you need to use FTP software.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631986.htmlTechArticleGeneral counter programs use the external program function exec(), but many host spaces (including paid ones) refuse This is a dangerous operation. We have to use fread(), fwrite() and other file reading and writing functions...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template