Page 1 of 1

PHP newbie - setcookie not working

Posted: Mon Nov 20, 2006 8:20 am
by juliaw
I suspect this is a really basic error, but I don't seem to be able to get the setcoockie function to work, I browse the following:

Code: Select all

<?php

setcookie( "vegetable","artichoke", time()+3600,"/", ".yourdomain.com",0);
 $display_block = $_COOKIE["vegetable"];

?>
<html>
<head>
<title>Secret Page</title>
</head>
<body>
<?php echo "$display_block"; ?>
</body>
</html>


and I get the following error:

Notice: Undefined index: vegetable in C:\Program Files\Apache Group\Apache2\htdocs\working\Exercises\login\testcookie.php on line 4


I have got cookies enabled,

What is my problem - can anyone help?

Julia

Posted: Mon Nov 20, 2006 2:50 pm
by feyd
$_COOKIE will not contain the value you just set until the next page request (provided the cookie took.)