PHP newbie - setcookie not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
juliaw
Forum Newbie
Posts: 5
Joined: Mon Oct 23, 2006 1:58 pm
Location: Portsmouth , UK

PHP newbie - setcookie not working

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$_COOKIE will not contain the value you just set until the next page request (provided the cookie took.)
Post Reply