Cookies

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
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Cookies

Post by Straterra »

I can properly set a cookie, but I cannot retrieve it. I get the error of Notice: Undefined index: testcookie in c:\ftp\users\straterra\cgi-bin\getbox2.php on line 2. The code for my cookie retrievel is
<?php
$cook = $_COOKIE['testcookie'];
echo $cook;
?>

And the code for saving the cookie is
<?php
$song = $_POST['dropdown'];
setcookie ("testcookie", $song);
echo $song;
print_r ($_COOKIE);
?>

If anyone could help, I would greatly appreciate it.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Do you refresh the page in between setting the cookie and trying to echo it's value?

Mac
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Yes, I do
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Do you get anything if you do:

Code: Select all

print_r($_COOKIE);
on the second page?

Mac
Post Reply