The problem with the page is that after I've implemented the statistics count, I want to use its output in my PHP-not-enabled pages, so what should I do? The main solution is to output a JavaScript script. This is useful, such as implementation of dynamic news, advertising polling, of course, this is about how to send a program download count to the non-PHP page.
The file format is:
index | filename Hint | link | count
Note that "|" is used here. Line separation. I am using a text file for processing. There may be a row of data in it:
file1| test file 1|. /download/file1.zip|10
As you can see, the number of downloads may already be 10 times. Now I want to output this 10 times to other pages.
Isn't it! After SRC refers to the output of the script, "?" The arguments for the incoming script are followed. So what data should output.php output to be executed? You should output JavaScript statements, such as document.write (). The browser then looks at the output of the output.php as a JavaScript program and processes it as if it were written directly, except that the script was obtained from somewhere else.
OK, know what kind of content should be output, you can write PHP program.
Step Two: Output results
$FP =fopen (".. /count/download.db "," R ");
$flag =false;
while (!feof ($FP))
{
$line =fgets ($FP, 256);
List ($index, $title, $url, $count) =split ("\|", $line);
if (Strtolower ($index) ==strtolower ($id))
{
$flag =true;
Break
}
}
Fclose ($FP);
if ($flag)
{
echo "document.write ($count);";
}
Else
echo "document.write" (\ "not found\"); ";
?>
This code is also simple, but there are a few points to explain. Open a file first. $flag indicates whether the file record for the specified index is found.
First set to False. Again a loop, provided the file does not end.
Then the body of the loop: Take out a line of text, preferably a long length. To split the fields to "|" As a separator. Note that the split function used is the regular expression, "|" is a special symbol used to use the "\" number. And then put them in the corresponding variables respectively. What we really care about here is $index and $count. Compares the input parameter $id with the retrieved index ($INDEX) and, if equal, sets the find flag to true and exits the loop. Otherwise find the next row of data.
At the end, close the file and output the appropriate JavaScript script based on whether the flag is found.
For the use of $id, PHP is automatically to call the URL of the id=xxx is processed, can be used directly. You can also use $http_get_vars[id].
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.