Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Php Programming Code Examples

Php > Complete Programs Code Examples

A Simple hit counter, which also outputs alt tags on images for text

A Simple hit counter, which also outputs alt tags on images for text <? $fileloc = "/home/mysite/hits.txt"; //| //| Change this to the url directory containing the images, including trailing / //| $imagedir = "http://www.mysite.com/images/"; //| //| If the counter is broken, or there is a problem, it will display nothing unless you set this to 1 //| $debug = 0; if(is_file($fileloc)) { if($hits = file($fileloc) AND $file = fopen($fileloc, "w")) { $hits = trim($hits[0]) + 1; fputs($file, $hits); $length = strlen($hits); fclose($file); $file = fopen($fileloc, "r"); echo "<table cellspacing=0><tr>\n"; for($repeat = 1; $repeat <= $length; $repeat++) { $number = fgetc($file); echo "<td><img src=\"$imagedir$number.gif\" alt=\"$number\"> \n"; } echo "</tr></table>\n"; fclose($file); } else { if($debug != 0) { echo "Error: Could not open the file, or file does not contain a valid number"; } } } else { if($debug != 0) { echo "Error: Hit file does not exist, or there has been a disk failure"; } } ?>