Talk about how to use PHP text counter remotely_PHP tutorial

WBOY
Release: 2016-07-13 17:23:56
Original
970 people have browsed it

We all must be aware of the powerful functions of PHP. You can easily write a text counter using it. However, this can only be used on sites where you can run PHP programs. How can you also use it on sites where you cannot run PHP? What about using it? Please read below:
In fact, this uses a JavaScript document.write function to display our count.
Insert an html language: where you need the counter. That's it. The following
is the source program of counter.php.

//---------------------------------------- ----------------------------
// Text counter
// Author: Xu Xiaodong (chinlone)
/ / Home page: 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 there is no counter.txt file, create it
fwrite($fp,"0");//Write the 0 value back to the file
fclose($fp);//Close the file
}
$fp = fopen($counterFile,"r");//Open the counter.txt file in reading mode
$num = fgets($fp,9);//Read the file pointer pointed to The length of the line (first line) is 9, and the value is given to the num variable
fclose($fp); //Close the file
$num++; //The value is increased by 1


$fp = fopen( $counterFile,"w+");
fwrite($fp,$num);//Write the new value back to the file
fclose($fp);//Close the file
echo "document.write( $num)";//Use JavaScript's document.write function
to display our count
?>
Passed under apache+PHP4.0

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532191.htmlTechArticleWe must all know the powerful functions of PHP. We can use it to easily write a text counter. But this can only be used on sites where you can run PHP programs, how to...
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