| | |
Simple website hit counter (PHP version)
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
This snippit is a follow up to my first snippit, namely "Simple website hit counter" which is written in Perl. It does exactly the same thing using PHP. "Boring", you might say? Well, I have my reasons for wanting to learn this language and one needs to start somewhere
. Also, it will give me a chance to compare how the two languages work for samll programs. If you want to make the counter work on your website you can grab the number tiles from my home page if you like (from the root URL load [0-9]tile.gif). Enjoy.
Steven.
. Also, it will give me a chance to compare how the two languages work for samll programs. If you want to make the counter work on your website you can grab the number tiles from my home page if you like (from the root URL load [0-9]tile.gif). Enjoy.Steven.
<?php main(); function main() { $data = ""; access_file("hit_count.txt", $data); for ($n = 0; $n < strlen($data); $n++) { $count[$n] = substr($data, $n, 1); } for ($n = 0; $n < 4 - strlen($data); $n++) { echo "<img src=\"0tile.gif\" alt=\"0\">"; } for ($n = 0; $n < strlen($data); $n++) { switch ($count[$n]) { case 0: $insert = "0"; break; case 1: $insert = "1"; break; case 2: $insert = "2"; break; case 3: $insert = "3"; break; case 4: $insert = "4"; break; case 5: $insert = "5"; break; case 6: $insert = "6"; break; case 7: $insert = "7"; break; case 8: $insert = "8"; break; case 9: $insert = "9"; break; default: $insert = "0"; } echo "<img src=\"" . $insert . "tile.gif\" alt=\"$insert\">"; } } function access_file ($filename, &$data) { $file1 = fopen($filename, "r+") or die ("Unable to open file $filename for read / write."); $data = fread($file1, filesize($filename)); $new_data = $data + 1; fseek($file1, 0, SEEK_SET); fwrite($file1, $new_data); fclose($file1); } ?>
Similar Threads
- PHP hit counter (PHP)
- PHP Hit Counter ISSUES. (PHP)
- Code Snippet: Simple website hit counter (Perl)
- Code Snippet: A Reeeeaaly simple Hit counter (PHP)
- PHP Server-Side Hit Counter for Beginner (PHP)
| Thread Tools | Search this Thread |
.htaccess ajax apache api array back basic beginner binary broken cakephp checkbox class cms code computing cron curl customizableitems database date delete display dynamic echo email error file files filter folder form forms function functions gc_maxlifetime google host href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory memory menu mlm mod_rewrite multiple mysql navigation oop parsing paypal pdf php problem query radio random recursion regex remote script search server sessions sms snippet soap source space sql syntax system table thesishelp trouble tutorial update upload url validation validator variable video web xml youtube



