simply put, setcookie() must be used before ANYTHING is output to the page.
for example, the following will not work because there is a newline before the PHP engine is engaged:
PHP Code:
<?php
setcookie(name,1,time()+3600);
?>
The following will work however, despite it not being the first bit of code (because nothing else was output before it):
PHP Code:
<?php
if (isset($_GET['name']))
$name = $_GET['name'];
else $name=0;
if (isset($_GET['age']))
$age = $_GET['age'];
$calcage = $age+5;
if ($name)
$output = "$name, in 5 years you will be $calcage years old!";
else
$output = 'please submit name & age';
setcookie(name,1,time()+3600);
echo $output;
?>