I had a home web server running on Windows XP recently, but I decided to move it to Ubuntu Linux, so I made an image of the hard drive, then installed Ubuntu, now after installing Apache2 and PHP5, I copied back all of my server files (.html and .php mostly), but now I am getting some errors for no apparent reason. I get an error in my PHP code whenever I try to make a cookie. I never had this problem before, and I changed no code...

My counter file is below, and I called it like "<?php $counterfile = "/home/browner87/Documents/apache2dir/counter/counter.dat"; $page = "home"; include'counter/counter.php'; ?>"

Code:
$imagedirectory = "/counter/";
$digits = 4;

//print_r(error_get_last());

$opencount = fopen($counterfile, "r");
$currentcount = fread($opencount, filesize($counterfile));
if($_COOKIE["$page"] != "set") 
{
	setcookie("$page", "set", 0);
	++$currentcount;

//$opencount = fopen($counterfile, "w");
fwrite($opencount, $currentcount);
//fclose($opencount);
}
fclose($opencount); //

//print_r($currentcount);

$newcount = $currentcount;
$numdigits = strlen($newcount);
if ($numdigits > $digits) {
        $newcount = "0";
        } else {
        }
$actdigits = strlen($newcount);

for ($a=0; ; $a++) 
{
        if ($a == $digits) 
	   {
                break;
        } 
	   else 
	   {
                $img[$a] = "$imagedirectory";
                $img[$a] .= "0.gif";
        }
}

for ($a=0; ; $a++) 
{
        if ($a == $actdigits) 
	   {
                break;
        } 
	   else 
	   {
                $showdig = substr($newcount, $a, 1);
                $img[$digits - $actdigits + $a] = "$imagedirectory";
                $img[$digits - $actdigits + $a] .= "$showdig.gif";
        }
}

$displayblock = "";
for ($a=0; $a < $digits; $a++)
{
        $displayblock .= "<td><img src=$img[$a]></td>";
}

$displayblock .= "<br />";
//$opennewcount = fopen($counterfile,"w");
//fwrite($opennewcount, $newcount);
//fclose ($opennewcount);
    echo $displayblock
I read a bit about not being able to make cookies after printing to the screen, but I don't want to rewrite my whole script from scratch (and rewrite every page with a counter on it). SO, what changed from going from XP to Ubuntu? Does XP have a hidden extra ability to send cookies after the header is gone? Can anyone provide a simple solution?