Fancy Hit Counter

December 22nd, 2009

Actually I wanted to write this article earlier. Because I do not understand exactly how this script work.

Fancy hit counter hit counter view that is no longer using the default font, but we use images that represent the numbers.

Well, after we get the results of calculations. So the numbers are converted to images by using the function str_replace (). Function str_replace () before I use to script bad word filter in the previous article.

Prepare the 10 images that representing the numbers 0 to 9. For example you could use my images. Put these pictures in the same folder


See the following script is the same as the unique script hit counter. I just added a few lines (marked in bold).

<?php
$server = “localhost”;
$username = “root”;
$password = “”;
$database = “test”;
//Connect database
mysql_connect($server,$username,$password) or die(”connection failed”);
mysql_select_db($database) or die(”Database cannot opened”);
$ddate= date(”Y-m-j”);
$ip   = $_SERVER["REMOTE_ADDR"];
$referer= $_SERVER["HTTP_REFERER"];

$sql_1= mysql_query(”SELECT * FROM counter WHERE ip=’$ip’ AND ddate=’$ddate’”);
$r= mysql_num_rows($sql_1);
//echo “banyak : $r<br>”;
if ($r == 0){
mysql_query(”INSERT INTO counter (ip,
referer,
ddate)
VALUES (’$ip’,
‘$referer’,
‘$ddate’)”);
}

$number      = array(”0″, “1″, “2″, “3″, “4″, “5″, “6″, “7″, “8″, “9″);
$fancy_number= array(”<img src=images/0.jpg>”, “<img src=images/1.jpg>”, “<img src=images/2.jpg>”, “<img src=images/3.jpg>”, “<img src=images/4.jpg>”, “<img src=images/5.jpg>”, “<img src=images/6.jpg>”, “<img src=images/7.jpg>”, “<img src=images/8.jpg>”, “<img src=images/9.jpg>”);

$sql_2    = mysql_query(”SELECT * FROM counter”);
//$all_count= mysql_num_rows($sql_2);
$fancy_all_count= str_replace($number, $fancy_number, “$all_count”);
echo “<h3>total views $fancy_all_count</h3> \n”;

$sql_3= mysql_query(”SELECT * FROM counter WHERE ddate=’$ddate’”);
$today_count= mysql_num_rows($sql_3);
$fancy_today_count= str_replace($number, $fancy_number, $today_count);
echo “<h3>today views $fancy_today_count</h3> \n”;
?>

The following table is used for hit counter

CREATE TABLE `counter` (
`id_counter` int(5) NOT NULL auto_increment,
`ip` varchar(16) collate latin1_general_ci NOT NULL,
`referer` varchar(255) collate latin1_general_ci NOT NULL,
`ddate` date NOT NULL,
PRIMARY KEY  (`id_counter`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ;


Featured Articles Make DB by Delphi File I/O Routines

>> Step by Step Create Your Own Database
>> Displaying Database On Tabular Mode
>> Delete A Record
>> Primary Key
>> Linking Tables
>> Create A Related Tables Refer By Current Position
>> Create A Related Tables Refer By Number Of Id Of Record In Tables
>> Quciksort