fooDigi Posted February 8, 2007 Share Posted February 8, 2007 i need a simple hit counter script, but for some reason firefox doubles the count every hit. opera and ie doesn't. this problem seems familiar, anyway, here's the code, thanks for any help... <?php header("Content-type: image/png"); header('Cache-Control: no-cache'); header('Pragma: no-cache'); # database // not shown # check user, grab count $que = "select `hit_count` from `counter` where `c_user` = 'test_site' limit 1"; $res = mysql_query($que); $r = mysql_result($res, 0, 'hit_count'); # increment value and update field in database $ques = "update `counter` set `hit_count` = `hit_count` + 1 where `c_user` = 'test_site'"; $ress = mysql_query($ques); # define directories define('FONTDIR','./lib/fonts/'); define('IMGDIR','./img/'); # font array $fonts = array( 'myriad.ttf' ); # init image $cimg = imagecreate(200,34); # text color array $text_colors = array( imagecolorallocate($cimg, 0, 166, 81), imagecolorallocate($cimg, 102, 153, 153), imagecolorallocate($cimg, 0, 126, 61), imagecolorallocate($cimg, 255, 0, 0), imagecolorallocate($cimg, 0, 0, 0), imagecolorallocate($cimg, 255, 255, 255) ); # background color array $back_colors = array( imagecolorallocate ($cimg, 51, 102, 102) ); # fill our background imagefill($cimg, 0, 0, $back_colors[0]); # output the count imagefttext($cimg, 24, 0, 5, 29, $text_colors[5], FONTDIR . $fonts[0], $r); # output to browser imagepng($cimg); ?> Quote Link to comment Share on other sites More sharing options...
fooDigi Posted February 8, 2007 Author Share Posted February 8, 2007 when i comment out all 'gd functionality' and just output the incremented value it works fine. Quote Link to comment Share on other sites More sharing options...
fooDigi Posted February 8, 2007 Author Share Posted February 8, 2007 fixed... somewhat. once i include it as an image on another page, it increments like it's supposed. but when i hit it the script directly, it increments by 2. i think, for some reason it is hitting the page twice. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.