| | |
A Reeeeaaly simple Hit counter
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Ok, this is about as simple as it gets. This is a hit counter for your page that stores the count in a simple text file of your choosing. No need for a database, MySQL or otherwise. No complicated rubbish. Just one single function and one single file to store the count. Thats it.
<?php /* first you will need to create a text file somewhere and give it a name obviously. In this example I will call it hits.txt */ $stored = "hits.txt"; /* The following function when called gets the text file named in the above variable '$stored', then opens it for reading and writing, saves its contents in variable $stuff closes it, then opens it again, adds 1 to $stuff, displays $stuff and then saves and closes the file again. */ function displayHitThingy($stored) { $fp = fopen($stored,rw); $stuff = fgets($fp,9999); fclose($fp); $fp = fopen($stored,w); $stuff += 1; print "$stuff"; fputs($fp, $stuff); fclose($fp); } /* Now you just display it on your page somewhere with the following */ ?> Page hits: <?php displayHitThingy($stored); ?> <?php /* Thats it. You can of course use it on more than one page, just remember to change the textfiles name for each e.g. page1.txt page2.txt and so on.. */ ?>
0
•
•
•
•
Reese
This script requires PHP support on your server to work.
If you have PHP enabled, you copy and paste the script above into the page where you want it.
You will probably need to be in 'code view' or whatever the equivalent is in the software you are using.
You then have to rename the script to have a .php extension instead of a .htm or .html
Be aware that any other links to this page will need to be updated to reflect the name change.
Hope this helps you out
Dave
This script requires PHP support on your server to work.
If you have PHP enabled, you copy and paste the script above into the page where you want it.
You will probably need to be in 'code view' or whatever the equivalent is in the software you are using.
You then have to rename the script to have a .php extension instead of a .htm or .html
Be aware that any other links to this page will need to be updated to reflect the name change.
Hope this helps you out
Dave
Similar Threads
- PHP hit counter (PHP)
- stat hit counter HELP (PHP)
- hit counter (Site Layout and Usability)
- Hit counter (JavaScript / DHTML / AJAX)
- Help!!!Need JSP Hit Counter (JSP)
| Thread Tools | Search this Thread |
ajax apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link list login mail mediawiki menu mlm multiple mycodeisbad mysql number oop paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search seo server sessions sms soap source sp space speed sql subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign websphere white xml youtube



