Home >Backend Development >PHP Tutorial >Using Php to implement link popularity statistics_PHP tutorial
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;$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
🎜>