I need to somehow combine these two scripts to get a cookie-based
counter whereby the counter script would know, via a cookie, that
the user had been ther before.
I've tried to combine them but keep getting the "Headers have already
been sent" error...
Can anyone help?
This is a text-based counter script that sets a cookie
if the user hasn't been before
<?
$fname="./count.txt";
$count=trim(implode("",@file("$fname")));
if(!$count) $count=0;
if(!$Counted){
setcookie("Counted", "yes", time() + (3600*24*7));
++$count;
$fp=fopen("$fname","w");
fputs($fp,$count);
fclose($fp);
}
echo $count;
?>
This is the counter script I use that combines
pngs for each char into a single png.
<?php
if (file_exists("counter.txt"))
{
$fp = fopen("counter.txt", "r");
$counter = fgets($fp, 999);
$tmp = $counter;
fclose($fp);
$fp = fopen("counter.txt", "w");
fwrite($fp, $tmp+=1);
fclose($fp);
}
$counter = number_format($counter);
$color = 'yellow';
header('content-type: image/png\n\n');
set_time_limit(250);
$dx = strlen($counter) * 16;
$dy = 22;
$im = @imagecreate($dx,$dy);
for ($count = 0; $count < strlen($counter); $count++)
{
$imgstr = 'images/digits/sm'.ord($counter[$count]).$color.'.png';
if (isset($test)) {
echo $imgstr.'<br>';
} else {
$im_tmp = @imagecreatefrompng($imgstr);
imagecopy($im, $im_tmp, $count*16, 0, 0, 0, 16, 22);
imagedestroy($im_tmp);
}
}
imagepng($im);
imagedestroy($im);
?>