Home  >  Article  >  Backend Development  >  Using js to call php content in HTML_PHP tutorial

Using js to call php content in HTML_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:40:00805browse

We often see that the statistical codes of many websites are displayed in the form of js calls. Let’s take a look at how to implement them.

  1. $countfile = "num.txt";//The file to define the counter is count.txt in the current directory, Then we should test whether the file can be opened
  2. if (($fp = fopen($countfile, "r ")) == false) { //Open the file in read-write mode, exit if it cannot be opened
  3. printf ("Failed to open file %s!",$countfile);
  4. exit;
  5. }else{
  6. $count = fread ($ fp,10); //If the file can be opened normally, read the data in the file, assuming it is 1
  7. $count = $count 1; //Read 10-bit data
  8. fclose ($fp);//Close the current file
  9. $fp = fopen($countfile, "w ");//Open the file in overwrite mode
  10. fwrite ($fp,$count) ;//Write the new data after adding 1
  11. ​​​ fclose ($fp);//And close the file
  12. ​​​ Echo document.write(".$count.")n;// Use javascript to output data
  13. }
  14. ?>
  15. Call the js method in the html file.
  16. Hello, you are the No.
  17. Visitors
  18. http://www.bkjia.com/PHPjc/486253.html
www.bkjia.com
true

http: //www.bkjia.com/PHPjc/486253.html

We often see that the statistical codes of many websites are displayed in the form of js calls. Let’s do it below Let’s see how that works out. ?PHP $countfile = "num.txt";//Define counter write...
Statement:
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