Jump to content

"simple hit counter"


fooDigi

Recommended Posts

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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.