Location: PHPKode > scripts > php easy :: total visits counter (graphic) scripts set > php-easy-total-visits-counter-graphic-scripts-set/iframe/visits.php
<?php
/*************************************************************************
php easy :: total visits counter (graphic) scripts set - HTML iFrame Version
==========================================================================
Author:      php easy code, www.phpeasycode.com
Web Site:    http://www.phpeasycode.com
Contact:     hide@address.com
*************************************************************************/

$dbfile = "visits.db";  // path to data file
$digits = "digits"; // path to folder containing digits images (1.gif, 2.gif etc.) from the root

if(!file_exists($dbfile)) {
	die("Error: Data file " . $dbfile . " NOT FOUND!");
}

if(!is_writable($dbfile)) {
	die("Error: Data file " . $dbfile . " is NOT writable! Please CHMOD it to 666!");
}

function CountVisits() {
	global $dbfile;
	$cur_ip = getIP();
	
	$dbary = unserialize(file_get_contents($dbfile));
	if(!is_array($dbary) || !in_array($cur_ip, $dbary)) { // new IP
		$dbary[] = $cur_ip;
		
		$fp = fopen($dbfile, "w");
		fputs($fp, serialize($dbary));
		fclose($fp);
	}
	
	$out = sprintf("%09d", count($dbary)); // format the result to display 9 digits with leading 0's
	
	return $out;
}

function getIP() {
	if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
	elseif(isset($_SERVER['REMOTE_ADDR'])) $ip = $_SERVER['REMOTE_ADDR'];
	else $ip = "0";
	return $ip;
}

function Str2Img($str, $imgdir) {
	$out = "";
	for($i=0; $i<strlen($str); $i++) {
		$out .= "<img src=\"/" . $imgdir . "/" . $str{$i} . ".gif\" alt=\"" . $str{$i} . "\" />"; // replace with images
	}
	return $out;
}

$total_visits = CountVisits();
?>
<html>
<head>
<title></title>
<style type="text/css">
body {
margin: 0;
}
</style>
</head>
<body>
<p>Total visits: <?=Str2Img($total_visits, $digits);?></p>
</body>
</html>
Return current item: php easy :: total visits counter (graphic) scripts set