I wanted to make an image counter (Like for craigs list or something) but for some reason, the count always goes up two.
<?php
error_reporting(E_ALL);
if(!isset($_GET['id'])){
$hits = "script-x.net";
$font = 'fonts/astronau.ttf';
}else{
$host = "@@@@@@@";
$user = "@@@@@@@";
$pass = "@@@@@@@";
$database = "@@@@@@@";
$con = mysql_connect($host,$user,$pass);
if(!$con){
die("FATAL ERROR:".mysql_error());
}else{
mysql_select_db($database,$con);
}
$id = mysql_real_escape_string(str_replace('.png','',$_GET['id']));
$id = str_replace('.jpg','',$id);
$get = mysql_query("SELECT * FROM table WHERE id = '".$id."'");
while($row = mysql_fetch_array($get)){
$hits = $row['hits'];
$font = 'fonts/'.$row['font'];
}
$hits++;
//$hits = $id;
mysql_query("UPDATE table SET hits = '".$hits."' WHERE id = '".$id."'");
}
$img = imagecreate(200, 30);
$background = imagecolorallocate( $img,255, 255, 255 );
$text_colour = imagecolorallocate( $img, 0, 0, 0 );
imagesetthickness ( $img, 3 );
imagettftext($img, 20, 0, 5, 24, $text_colour, $font, $hits);
//header( 'Content-type: image/jpeg' );
header('Content-type: image/png');
//imagejpeg( $img );
imagepng($img);
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $img );
?>
It can be access at http://script-x.net/craigslist/1.jpg (with mod rewrite) or at http://script-x.net/craigslist/counter.php?id=1
It happens either way. Anybody see why?