This counter has no MySQL and is ment to be included wherever you want it to display/count a hit. It displays the output with the correct comma's (EG: 34,000)
By : DrEvele
<?php /*************************************************** ** Copyright (c) 2005, Jeff Johnson (jeffsworld.net) ** All rights reserved. ** ** Redistribution and use in source and binary forms, ** with or without modification, are permitted provided that the following ** conditions are met: ** ** Redistributions of source code must retain the above copyright notice, ** this list of conditions and the following disclaimer. ** Redistributions in binary form must reproduce the above copyright notice, ** this list of conditions and the following disclaimer in the documentation ** and/or other materials provided with the distribution. ** Neither the name of the JEFFSWORLD nor the names of its contributors ** may be used to endorse or promote products derived from this software without ** specific prior written permission. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, ** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR ** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS ** BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, ** OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT ** OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; ** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE ** OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, ** EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ** ****************************************************/ // Only needed for under php5 use: function str_split($the_string, $the_number) { $startoff_nr = 0; $the_output_array = array(); for($z = 1; $z < ceil(strlen($the_string)/$the_number)+1 ; $z++) { $startoff_nr = ($the_number*$z)-$the_number; $the_output_array[] = substr($the_string, $startoff_nr, $the_number); } return($the_output_array); } // Hit file (chmod a+rw to it) $count_my_page = ("/home/ytslfazk/public_html/dotblog/hits.txt"); // Read contents $hits = file($count_my_page); // Increase hits $hits[0]++; // Open for write $fp = fopen($count_my_page , "w"); // Save new value fputs($fp , "$hits[0]"); // Close file fclose($fp); // Explained: It's reversed so we can split it into 3's // and not have 3400 turn into 340,0 $hits_expanded = str_split(strrev($hits[0]), 3); for ($i = 0; $i <= sizeof($hits_expnaded) + 1; $i++) { if (isset($hits_string)) // Set the string back to normal. // NOTE: The newly added number goes _INFRONT_ of the old one because it // was reversed. $hits_string = strrev($hits_expanded[$i]).','.$hits_string; else // Set the string back to normal $hits_string = strrev($hits_expanded[$i]); } echo '<b>'.$hits_string.'</b>'; ?>
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.