Article Collection of three PHP counter code, all of them three have a common point is all without a database, but the use of text files to instance the page view count Oh.
The article collects three PHP tutorial counter code, they all three have a common point is all without the database tutorial, but the use of text files to instance the page view count Oh.
//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 ();
?>
Code two
$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);
?>
Code Three
$counterfile = "Www.bkjia.com.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);
?>
http://www.bkjia.com/PHPjc/444831.html www.bkjia.com true http://www.bkjia.com/PHPjc/444831.html techarticle article collection of three PHP counter code, all of them three have a common point is all without a database, but the use of text files to instance the page view count Oh. The article has collected three models ...