Page counter principle
Author: Unknown from: World Resources Network collected Published: 2004-8-17 0:21:00 (excerpt from CCU newsgroups, may have been the source of Taiwan published a book about PHP: PHP book) is a visitor counter Let Web visitors know the most direct way to the popularity of this web page or website. Especially those who want to make money with web pages, the number of visitors is the best words of advertisers. Of course, you can write the number of websites to a statistical report, but always feel that it is more realistic, and I've seen it asks. In the above figure, the flow of the visitor counter is as follows 1. The first user browses a page. 2. The server is read from the database or file to the number of times the page is viewed. 3. Add a number of times, and send it back to the first user. 4. The second user browses a page. 5. The server reads the number of times the page is read from the database or file. 6. Plus the number of times, and send it back to the second user. PHP does not have a special visitor counter, but we can write a guest counter file with PHP's powerful feature. The following functions are the prototype of the visitor counter, which is provided by David W. Bettis and has been modified by the author.
For example, you have to set all the include files in http://abdefghijk.com.tw/include, you can add the following example php3_include_path in httpd.conf.: ./ include: ../ INCLUDE Don't forget to restart Apache Server The new include path is valid. ./apachectl restart is then placed in the server's ... / incrude directory, the file name is copied below is mycounter () in the mYcounter (). In order to make the reader easy to understand, the variables in the program $ Counterfile, $ FP, and $ NUM are kept the same as the variable function in the counter set by David W. Bettis. php file: // --------------------------- // Visitor counter Funny mycounter () // Author: Wilson Peng / / Copyright (c) 1999 File: // -------------------------- Function mycounter () {$ counterfile = "/ tmp". $ GLOBALS ["PHP_SELF"]; if (! File_exists) {if (! File_exists)) {mkdir ($ counter ($ counterfile), 0700);} EXEC ("echo 0> $ ");} $ fp = fopen ($ counter," rw "); $ num = fgets ($ fp, 5); $ NUM = 1; Print" $ Num "; Echo $ Counterfile; Exec (" RM - Rf $ counter "); EXEC (" Echo $ NUM> $ Counterfile ");}?> Copyright? 1999, Wilson Peng, Of course, if you want to add the MyCounter () in Homepage, you can use it. PHP Require ("counter.inc");?>