•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 374,572 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,817 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
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.
Last edited : Feb 7th, 2007.
<?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); } ?>
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)