i made a very basic hit counter, it works fine, untill i try to print the count on an image and send it to the use
<?php
$datalog = explode(",",file_get_contents("mi_datalog.txt"));
$views = $datalog[0]+1;
$last_act = time()-$datalog[1];
if($last_act>=86400)$last_act = round(($last_act-($last_act%86400))/86400)." days";
elseif($last_act>=3600)$last_act = round(($last_act-($last_act%3600))/3600)." hours";
elseif($last_act>=60)$last_act = round(($last_act-($last_act%60))/60)." minutes";
else $last_act .= " seconds";
$my_time = date("h:i:s a");
$nst = date("h:i:s a",time()-68400);
$my_np = "11,942";
$fp = fopen("mi_datalog.txt","w");
fwrite($fp,$views.",".$datalog[1]);
fclose($fp);
$im = imagecreatefrompng("base.png");
$textcolor = imagecolorallocate($im, 62, 29, 0);
$font = imageloadfont("font.gdf");
imagestring($im, $font, 82, 38, $views, $textcolor);
imagestring($im, $font, 82, 50, $nst, $textcolor);
imagestring($im, $font, 82, 69, $my_np, $textcolor);
imagestring($im, $font, 82, 81, $last_act, $textcolor);
imagestring($im, $font, 82, 93, $my_time, $textcolor);
header("Content-type: image/png");
imagepng($im);
?>
this doesnt work, it jumps up 2 counts insted of just 1.
<?php
$datalog = explode(",",file_get_contents("mi_datalog.txt"));
$views = $datalog[0]+1;
$last_act = time()-$datalog[1];
if($last_act>=86400)$last_act = round(($last_act-($last_act%86400))/86400)." days";
elseif($last_act>=3600)$last_act = round(($last_act-($last_act%3600))/3600)." hours";
elseif($last_act>=60)$last_act = round(($last_act-($last_act%60))/60)." minutes";
else $last_act .= " seconds";
$my_time = date("h:i:s a");
$nst = date("h:i:s a",time()-68400);
$my_np = "11,942";
$fp = fopen("mi_datalog.txt","w");
fwrite($fp,$views.",".$datalog[1]);
fclose($fp);
$im = imagecreatefrompng("base.png");
$textcolor = imagecolorallocate($im, 62, 29, 0);
$font = imageloadfont("font.gdf");
imagestring($im, $font, 82, 38, $views, $textcolor);
imagestring($im, $font, 82, 50, $nst, $textcolor);
imagestring($im, $font, 82, 69, $my_np, $textcolor);
imagestring($im, $font, 82, 81, $last_act, $textcolor);
imagestring($im, $font, 82, 93, $my_time, $textcolor);
die($views);
header("Content-type: image/png");
imagepng($im);
?>
in this one the counter works, yet all i did was kill the script just before its returned as an image, i just dont get whats going on.
there is somthing in that very last line imagepng that makes the count, (one that should of already been writen) just up 1 more, then get writen.