2011-05-02, 08:01 AM
I have a little hit counter script, but it doesnt seem to be working. When the image sis loaded it should add 1 to the value in the DB, but it is adding 2...
EDIT: OK, this ONLY happens when the image is loaded directly, im thinking this is a browser issue
<?php
$con = mysql_connect("localhost","tracke****","*********");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("tracker_stats", $con);
$day = date("j");
$month = date("n");
$result = mysql_query("SELECT * FROM stat WHERE id = '".$month."'") or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_BOTH);
$update = mysql_query("UPDATE stat SET `".$day."` = '".($row[$day] + 1)."' WHERE id = '".$month."'");
$update2 = mysql_query("UPDATE stat SET `total` = '".($row['total'] + 1)."' WHERE id = '".$month."'");
if (!$update)
{
die('Could not connect: ' . mysql_error());
}
mysql_close($con);
$im = imagecreatetruecolor(1, 1);
$red = imagecolorallocate($im, 255, 0, 0);
$black = imagecolorallocate($im, 0, 0, 0);
imagecolortransparent($im, $black);
header( "Content-type: image/png" );
imagepng( $im );
imagedestroy( $im );
?>
EDIT: OK, this ONLY happens when the image is loaded directly, im thinking this is a browser issue