// compteur
function CountMe($Base,$URL) {
require("db_inc.php3");
if(!mysql_connect($db_server,$db_user,$db_pw)){
print " erreur acces Mysql
";
exit;
}
if(!mysql_select_db($db)){
print "erreur choix base
";
exit;
}
if (strlen($URL)>0 && strcmp(substr($URL,strlen($URL)-1),"/")==0) $URL = $URL . "index.html";
$result=mysql_query("SELECT * FROM Count WHERE Base='$Base' AND URL='$URL'");
while ($row = mysql_fetch_row($result)) {
$ChkBase=$row[0];
$ChkURL=$row[1];
$ChkCount=$row[2];
$Count=$ChkCount;
}
if ($ChkBase == "" && $ChkURL == "") {
mysql_query("INSERT INTO Count VALUES ('$Base','$URL','0')");
$Count=0;
}
$Count++;
mysql_query("UPDATE Count SET Number='$Count' WHERE Base='$Base' AND URL='$URL'");
$result=mysql_query("SELECT * FROM Count WHERE Base='$Base' AND URL='$URL'");
while ($row = mysql_fetch_row($result)) {
$Base=$row[0];
$URL=$row[1];
$Count=$row[2];
}
if ($Count < "10") {
$length="1";
} elseif ($Count > "9" AND $Count < "100") {
$length="2";
} elseif ($Count > "99" AND $Count < "1000") {
$length="3";
} elseif ($Count > "999" AND $Count < "10000") {
$length="4";
} elseif ($Count > "9999" AND $Count < "100000") {
$length="5";
} elseif ($Count > "99999" AND $Count < "1000000") {
$length="6";
} elseif ($Count > "999999" AND $Count < "10000000") {
$length="7";
} elseif ($Count > "9999999" AND $Count < "100000000") {
$length="8";
} else {
$length="9";
}
// generation de l'image avec GD
Header( "Content-type: image/gif");
if ($length == "1") {
$im = imagecreate(14,20);
$black = ImageColorAllocate($im, 0, 0, 0);
imagefill($im,0,0,$black);
} elseif ($length == "2") {
$im = imagecreate(24,20);
$black = ImageColorAllocate($im, 0, 0, 0);
imagefill($im,0,0,$black);
} elseif ($length == "3") {
$im = imagecreate(33,20);
$black = ImageColorAllocate($im, 0, 0, 0);
imagefill($im,0,0,$black);
} elseif ($length == "4") {
$im = imagecreate(41,20);
$black = ImageColorAllocate($im, 0, 0, 0);
imagefill($im,0,0,$black);
} elseif ($length == "5") {
$im = imagecreate(50,20);
$black = ImageColorAllocate($im, 0, 0, 0);
imagefill($im,0,0,$black);
} elseif ($length == "6") {
$im = imagecreate(59,20);
$black = ImageColorAllocate($im, 0, 0, 0);
imagefill($im,0,0,$black);
} elseif ($length == "7") {
$im = imagecreate(68,20);
$black = ImageColorAllocate($im, 0, 0, 0);
imagefill($im,0,0,$black);
} elseif ($length == "8") {
$im = imagecreate(77,20);
$black = ImageColorAllocate($im, 0, 0, 0);
imagefill($im,0,0,$black);
} else {
$im = imagecreate(86,20);
$black = ImageColorAllocate($im, 0, 0, 0);
imagefill($im,0,0,$black);
}
$white = ImageColorAllocate($im, 255, 255, 255);
ImageString($im,5,3,2,$Count,$white);
ImageGif($im);
ImageDestroy($im);
}
// on decode les parametres
// on recupere le referer qu'on analyse
$param=parse_url(getenv("HTTP_REFERER"));
CountMe($param["scheme"]."://".$param["host"],$param["path"]);
?>