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
https://forums.phpfreaks.com/topic/37587-simple-hit-counter/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.