How to remotely use PHP text counters _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
This article describes how to remotely use PHP text counters. We all know the powerful functions of PHP. using it, you can easily write a text-type counter, but this can only be used at the site where you can run the PHP program, we all know how to use PHP's powerful functions. using it, you can easily write a text-type counter, but this can only be used at the site where you can run the PHP program, how can I use PHP on websites that you cannot run? Please refer to the following link:
In fact, this uses a JavaScript document. write function to display the count.
Insert an html language where you need the counter. Below
It is the source program of counter. php.
//--------------------------------------------------------------------
// 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"); // Create a counter.txt file if it does not exist.
Fwrite ($ fp, "0"); // write the value 0 back to the file.
Fclose ($ fp); // close the file
}
$ Fp = fopen ($ counterFile, "r"); // open the counter.txt file as a reader
$ Num = fgets ($ fp, 9); // The Row indicated by the read object pointer (the first line) is 9 and the value is paid 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 the document. write function of JavaScript
Number to display our count
?>
Run the following command in apache + PHP4.0:

...

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.