This page has been accessed 6,233 times since the 5th December 2003.
| View this page in: |
English |
Chinese |
Dutch |
French |
German |
Greek |
Italian |
Japanese |
Korean |
Portuguese |
Russian |
Spanish |
Translation to non-English languages provided by Babelfish on Altavista
|
|
After a few hours digging around the docs of this thing called PHP (which AFAICS is C with webby bits on), I came up with what is below. Indeed, the very web counter you see at the top of every page on nedprod.com runs off the same! Features:
Since it's so small, I'm not even going to offer it as a download - you can simply copy & paste it from here. Note that this is a live copy - I have some PHP mangle the actual version in usage onto this page: Please note that this is my very first ever PHP program and so may contain errors! Installation:Simply place the above into a "counter.php" file and place within a directory called "private" within your public_html directory. Now copy the following text into a file called ".htaccess" inside your private directory: <Limit GET POST> order deny,allow deny from all </Limit> <Limit PUT DELETE> order deny,allow deny from all </Limit> This ensures that no one can open the counter.php file directly and so read your password. If your server is not running Apache then this won't work - if you're on IIS, well quite frankly change to Apache (it runs on Windows too!). Next, you must customise your counter.php file to reflect your system's configuration. All the relevant parts are at the top of the file - you'll need to specify your base URL so that queries to the database are from the root of your particular site (ie; if your site is on http://www.mysite.net/~foo then this will be /~foo). Next you will need to specify which MySQL database to use plus its username and its password. Chances are you won't need to alter $dbhost nor $dbtable if the database is running on the same server hosting your website. You must now create the counters table in the database you just entered. Open that database and run the following SQL query: CREATE TABLE counters ( id int(10) unsigned DEFAULT '' NOT NULL auto_increment, page varchar(255) , count bigint(20) unsigned DEFAULT '0' NOT NULL , created date DEFAULT '0000-00-00' NOT NULL , PRIMARY KEY (id) ); Last thing to do is how to insert the web counter into your pages. Open your page in HTML form and at where you want it, insert: <?php include("<path to home account>/public_html/private/counter.php"); ?>
Usually the path to your home account on the server is "/home/<username>". You should now find that when opening the page, the text "<n> times since the <date>th <month> <year>" will appear where you placed the PHP insert. The value will increment and the date is set to the first time a query is made ie; if the page is not in the table, it gets added with today's date. You can of course manually edit the database and replace the figures with any you like. It's best to play with all this using one test page first before deploying across your website. Note: This code is provided in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantibility or fitness for a particular purpose. If you lose any data as a result of this code, it's not my fault though I welcome bug reports. Getting Apache to execute PHP inserts inside HTML pages:Something which I scratched my head over, so I'm saving you the bother - insert the following into a ".htaccess" file at the ROOT of your web site: AddType application/x-httpd-php .html .php .htmAnd that's all there is to it! |