Use js to call php content in HTML

Source: Internet
Author: User

We often see that the Statistical Code of many websites is displayed in the form of js calls. Let's take a look at how the example works.

  1. <? PHP
  2. $ Countfile = "num.txt"; // The file written by the counter is count.txt under the current directory. Then, we should test whether the file can be opened.
  3. If ($ fp = fopen ($ countfile, "r") = false) {// open the file in read/write mode. if the file cannot be opened, exit.
  4. Printf ("opening file % s failed! ", $ Countfile );
  5. Exit;
  6. } Else {
  7. $ Count = fread ($ fp, 10); // if the file can be opened normally, the data in the file will be read. Assume It is 1
  8. $ Count = $ count 1; // read 10-Bit Data
  9. Fclose ($ fp); // close the current file
  10. $ Fp = fopen ($ countfile, "w"); // open the file in overwrite mode.
  11. Fwrite ($ fp, $ count); // write new data after 1
  12. Fclose ($ fp); // close the file
  13. Echo document. write (". $ count.") n; // output data in javascript format
  14. }
  15. ?>
  16. In the html file, js calls the method.
  17. <HTML>
  18. <HEAD>
  19. <TITLE> example of page separation counter </TITLE>
  20. </HEAD>
  21. <BODY>
  22. Hello, you are the first
  23. <Script language = "JavaScript" src = "FileCount. php"> // pay attention to the server and directory path of the php counter when referencing. </SCRIPT>
  24. Visitor
  25. </BODY>
  26. </HTML>

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.