PHP Implementation Counter Method Summary, PHP counter Summary
The example of PHP implementation counter is described in this paper. Share to everyone for your reference. Specific as follows:
This collection of three PHP counter code, all of them three have a common point is that all do not need a database, but the use of text files to achieve web browsing count.
The first PHP counter code is as follows:
Copy CodeThe code is as follows: <?php
Counter
function Countx ($file = "Count.dat") {
if (file_exists ($file)) {
$FP =fopen ($file, "R");
$numx =fgets ($FP, 10);
Fclose ($FP);
$numx + +;
The above four lines of code can be replaced by an expression: $numx =file_get_contents ($file) +1;
}
else{
$NUMX = 1;}
File_put_contents ($file, $NUMX);//When the file does not exist, this function automatically creates the file, and automatically turns the parameter into a string write.
Echo $numx;
/* The entire function body can be replaced by two expressions: File_exists ($file)? file_put_contents ($file, file_get_contents ($file) +1): File_put_contents ($ File, "1"); ReadFile ($file);
*/
}
Function call
Countx ();
?>
The second PHP counter, the code is as follows:
Copy CodeThe code is as follows: <?php
$counterfile = "Balong.txt";//the file name of the stored value several paths
function Displaycounter ($counterfile) {
$fp = fopen ($counterfile, "RW");
$num = Fgets ($fp, 5);
$num + = 1;
Print "You are the first". " $num "." A guy looking at the Bahan counter ";
EXEC ("Rm-rf $counterfile");
EXEC ("echo $num > $counterfile");
}
if (!file_exists ($counterfile)) {
EXEC ("Echo 0 > $counterfile");
}
Displaycounter ($counterfile);
?>
The third PHP counter code is as follows:
Copy CodeThe code is as follows: <?php
$counterfile = "Www.jb51.net.txt";//the file name of the stored value several paths
function Displaycounter ($counterfile) {
$fp = fopen ($counterfile, "RW");
$num = Fgets ($fp, 5);
$num + = 1;
Print "You are the first". " $num "." A guy looking at the Bahan counter ";
EXEC ("Rm-rf $counterfile");
EXEC ("echo $num > $counterfile");
}
if (!file_exists ($counterfile)) {
EXEC ("Echo 0 > $counterfile");
}
Displaycounter ($counterfile);
?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/937727.html www.bkjia.com true http://www.bkjia.com/PHPjc/937727.html techarticle PHP Implementation Counter method Summary, PHP counter Summary The example of this article describes the PHP implementation of the counter method. Share to everyone for your reference. Here are the following: three PHP counts are collected here ...