We must all know PHP's powerful function, using it can easily write a text-type counter out, but this can only be used in the site you can run the PHP program to use, how can you not run PHP site can also use it? Please look down:
In fact, this uses a JavaScript document.write function to display our count.
Insert an HTML language where you need the counter: Yes. Below
Is the source of the counter.php program.
//--------------------------------------------------------------------
Text counter
Author: Xu Xiaodong (Chinlone)
Home: http://lthx.126.com
E-mail:chinlone@china.com
oicq:4703122
//--------------------------------------------------------------------
$counterFile = "Counter.txt";//File name
if (!file_exists ($counterFile)) {
$fp = fopen ($counterFile, "a");//If you do not counter.txt this file, create it
Fwrite ($FP, "0");//and write 0 value back to file
Fclose ($FP);//Close file
}
$fp = fopen ($counterFile, "R");//Read mode open counter.txt file
$num = Fgets ($fp, 9);//Read the file pointer refers to the line (the first line) length is 9, the value is paid to the NUM variable
Fclose ($FP);//Close file
$num ++;//value increased by 1
$fp = fopen ($counterFile, "w+");
Fwrite ($fp, $num);//writes the new value back to the file
Fclose ($FP);//Close file
echo "document.write ($num)";//document.write letter using JavaScript
Number to show us the count.
?>
Under the apache+php4.0
http://www.bkjia.com/PHPjc/532191.html www.bkjia.com true http://www.bkjia.com/PHPjc/532191.html techarticle We must all know PHP's powerful function, use it can easily write a text-type counter out, but this can only be used in the site you can run the PHP program, how to ...