Talk about how to use PHP text-type counters remotely _php tutorials

Source: Internet
Author: User
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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.