This is a image counter which is put in a page simply by using the
IMG tag in html. You don’t have to change the htm or html extension of your page to php.
- Need create a database and table “counter” in mySQL database server.
CREATE TABLE `yourdatabasename`.`counter` (
`ID` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`counter`INTEGER (9) NOT NULL default ‘0′,
PRIMARY KEY (`ID`)
);
UPDATE `yourdatabasename`.`counter` SET counter=0;
- Create a folder under root of your web server call “counter” .
- Feel free to use my script below (have to remove these “//” at begin of the lines ) and save as login.php into a folder call “counter”.
//<?php //login.php
//
// /**
// * @author PCS-PC
// * @copyright 2011
// */
//
//$db_hostname = ‘your database hostname’;
//$db_database = ‘your database name’;
//$db_username = ‘your database username’;
//$db_password = ‘your database password’;
//
//?>
- Feel free to use my script below (have to remove these “//” at begin of the lines ) and save as counter.php into a folder call “counter” .
//<?php //counter.php
//
// /**
// * @author PCS-PC
// * @copyright 2011
// */
//
//require_once ‘login.php’;
//$tbl_name = “counter”; //Table name
//
//
//$digit_dir = “./iphone”;
//$min_width = 5;
//$lifetime = 30;
//$domain = www.your_domain;
//$trigger = 1000;
//
//// Connect to server and select database.
//$db_server = mysql_connect($db_hostname, $db_username, $db_password);
//
//if (!$db_server)
// die(“cannot connect to server:
//” . mysql_error());
//
//mysql_select_db($db_database)
//or die(“Unable to select database: ”
//.mysql_error());
//
//$sql = “SELECT * FROM $tbl_name”;
//$result = mysql_query($sql);
//
//if (!$result)
// die(“Databasse access failed: ” . mysql_error());
//
//$rows = mysql_fetch_array($result);
//$count = $rows['counter'];
//
//// if have no counter value set counter = 1
//if (!($count))
//{
// $count = 1;
// $sql1 = “INSERT INTO $tbl_name(counter) VALUES(‘$count’)”;
// $result1 = mysql_query($sql1);
//}
//
//
//if (!isset($_COOKIE['counter']))
//{
// $count++;
// $sql2 = “update $tbl_name set counter=’$count’”;
// $result2 = mysql_query($sql2);
// mysql_close();
// setcookie(“counter”, “dummy”, time() + 60 * 60 * 24 * $lifetime, $domain);
//}
//
//$len = strlen(strval($count));
//if ($len > $min_width)
// $width = $len;
//else
// $width = $min_width;
//
//
//
//
//// Check image type (gif or png)
//if (!file_exists(“$digit_dir/0.gif”) && !file_exists(“$digit_dir/0.png”))
//{
// die(“No images in digit-dir”);
//}
//if (!file_exists(“$digit_dir/0.gif”))
//{
// //proceed_png();
// $d0 = ImageCreateFrompng(“$digit_dir/0.png”);
//
//
// $dx = ImageSX($d0);
// $dy = ImageSY($d0);
//
// $img = ImageCreateTrueColor($width * $dx, $dy);
// ImageDestroy($d0);
//
// $xoff = $width * $dx;
// while ($xoff > 0)
// {
// $digit = $count % 10;
// $count = $count / 10;
//
// $temp = ImageCreateFrompng(“$digit_dir/$digit.png”);
// $xoff = $xoff – $dx;
// ImageCopyResized($img, $temp, $xoff, 0, 0, 0, $dx, $dy, $dx, $dy);
// ImageDestroy($temp);
// }
//
// Header(“Content-type: image/png”);
// Imagepng($img);
// ImageDestroy($img);
//
//} else
//{
// //proceed_gif();
// $d0 = ImageCreateFromgif(“$digit_dir/0.gif”);
//
// $dx = ImageSX($d0);
// $dy = ImageSY($d0);
//
// $img = ImageCreateTrueColor($width * $dx, $dy);
// ImageDestroy($d0);
//
// $xoff = $width * $dx;
// while ($xoff > 0)
// {
// $digit = $count % 10;
// $count = $count / 10;
//
// $temp = ImageCreateFromgif(“$digit_dir/$digit.gif”);
// $xoff = $xoff – $dx;
// ImageCopyResized($img, $temp, $xoff, 0, 0, 0, $dx, $dy, $dx, $dy);
// ImageDestroy($temp);
// }
//
//
// Header(“Content-type: image/gif”);
// Imagegif($img);
// ImageDestroy($img);
//}
//
//
//?>
- Feel free to use my counter images iphone or design them ( they can be .gif or .png) by yourself and place them into folder “iphone” under “counter” folder .
- On your home page wherever you like to display the Hit Counter enter the code as below (have to remove these “//” at begin of the lines):
//<p>
// <img src=”counter/counter.php” alt=”counter” border=”0″ />
//</p>
- Save your home page and upload all files to your web server and enjoy.







