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.
- $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
- if (($fp = fopen($countfile, "r ")) == false) { //Open the file in read-write mode, exit if it cannot be opened
- printf ("Failed to open file %s!",$countfile);
- exit;
- }else{
- $count = fread ($ fp,10); //If the file can be opened normally, read the data in the file, assuming it is 1
- $count = $count 1; //Read 10-bit data
- fclose ($fp);//Close the current file
- $fp = fopen($countfile, "w ");//Open the file in overwrite mode
- fwrite ($fp,$count) ;//Write the new data after adding 1
- fclose ($fp);//And close the file
- Echo document.write(".$count.")n;// Use javascript to output data
- }
- ?>
- Call the js method in the html file.
- Hello, you are the No.
- Visitors
-
-
-
-
- http://www.bkjia.com/PHPjc/486253.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/486253.html
TechArticleWe 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