I've been trying to do a simple cookie demo, just to see how they work using the following script:
<?
if (!isset($localcook)) {
if (!$name) {
?>
<form method="post" action="<? print $PHP_SELF; ?>">
Name:<input type="text" name="name"><br>
<input type="hidden" name="task" value="set">
<input type="submit" value="Set that cookie!">
</form>
<?
} else {
setcookie("localcook",$name,time()+3600,"/");
header("location: $PHP_SELF");
}
} else {
print "Name: ".$localcook;
}
?>
But it returns:
Warning: Cannot add header information - headers already sent by (output started at c:\apache\htdocs/dev/cookie.php:9) in c:\apache\htdocs/dev/cookie.php on line 20
Warning: Cannot add header information - headers already sent by (output started at c:\apache\htdocs/dev/cookie.php:9) in c:\apache\htdocs/dev/cookie.php on line 21
Can anyone give me a hand with this?