The first thing to note: This is not the homepage counter, although the principle and it is the same.
A: Prepare a count file, store the URL of the link and the number of visits, formatted as follows
Id|url|count
The ID is used to find the index number, the URL is the address of the actual file, count is the number of
Instance data:
Doc01|docs/doc01.html|10
Doc02|docs/doc02.html|10
Two: Prepare the count.php file with the following code:
Function: Pass in the parameter ID, find the corresponding URL in the Count file, increment the count, and return the actual link
$countfile = "Count.txt";
$lines =file ($countfile);//reads the contents of the count file into the array $lines
for ($i =0; $i {
List ($sid, $url, $count) =explode ("|", $lines [$i]);
The decomposition string is $id, $url, $count
if ($sid = = $id)//find the specified ID
{
$count +=1; Increase Count
$lines [$i]= $sid. "|" . $url. "|" . "$count". "\ n";//Regenerate Count string
Break
}
}
Write count information
$FP =fopen ($countfile, "w");
for ($i =0; $i Fputs ($fp, $lines [$i]);
Fclose ($FP);
Header ("Location: $url");
?>
Note: This is an incomplete version on phpuser.com, I added some changes, it should be available now.
Third: The hyperlink in the home page should be called as follows:
Doc01
The program functions are:
First, read the contents of the count file into the array
Then find the specified ID number from the array, if found the true link to the corresponding file, and then add 1 to the count,
Regenerate count information
Writes the count information to the file
Return link
Four: The number of visitors quoted is the following sentence, write a function can also, I stole a lazy,
Who wrote it? Give me a:)
$countfile = "Count.txt";
$lines =file ($countfile);
List ($sid, $url, $count) = Explode ("|", $lines [0]);//$lines [0] corresponds to Count.txt
First record
Echo $count;
?>
http://www.bkjia.com/PHPjc/315455.html www.bkjia.com true http://www.bkjia.com/PHPjc/315455.html techarticle The first thing to note: This is not the homepage counter, although the principle and it is the same. A: Prepare a count file, store the link URL and the number of visits, format as follows Id|url|count ID is used to check ...