Home >Backend Development >PHP Tutorial >Using Php to implement link popularity statistics_PHP tutorial

Using Php to implement link popularity statistics_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:06:16814browse

First of all, let me explain: This is not a homepage counter, although the principle is the same.
1: Prepare a count file to store the URL of the link and the number of visits. The format is as follows:                                  ​​​​
id is the index number used to search, url is the address of the actual file, and count is Number of times
Instance data: doc01.html|10                                               ​​​?php                                                                                                          
$countfile="count.txt";                                      $countfile);//Read the contents of the count file into the array $lines                                                                                                      🎜>{                                                                                                        $url, $count)=explode("|", $lines[$i]);// Decompose the string into $id, $url, $count                                                                                                                                                                                                                                                                                   $lines[$i]=$sid . "|" . $url . "|" . "$count" . "n";//Regenerate the count string                                                                                                                                 🎜>}                                                                                
//写入计数信息                                                                   
$fp=fopen($countfile, "w");                                                      
for($i=0;$ifputs($fp, $lines[$i]);                                                          
fclose($fp);                                                                     
Header("Location: $url");                                                        
?>                                                                               
注:这个是phpuser.com上的不完全版本,我加了一些改动,现在应该是能用的。

Three: The calling method of the hyperlink on the homepage should be changed to:                                    The program functions are:
First read the content of the counting file into the array                                                                                                                                                                                                                                                      
Write the counting information into the file
Return to the link

Four: The number of visitors is the following sentences. It is also possible to write a function. Give me one :)                                                                                                                                                                                                                                                      ) = explode("|",$lines[0]);//$lines[0] corresponds to count.txt
                                                                                                                                                                                                       🎜>




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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/315455.htmlTechArticleFirst of all, let me explain: This is not a homepage counter, although the principle is the same as it. 1: Prepare a counting file to store the URL of the link and the number of visits. The format is as follows id|url|count id is used to check...
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