Forum Moderators: coopster

Message Too Old, No Replies

bah! why don't cookies work in PHP for me?

         

partha

9:04 pm on Feb 26, 2005 (gmt 0)

10+ Year Member



I'm just using W3C's simple tutorial:

page1
-----------
<?php
setcookie("uname", $name, time()+36000);
?>

page2
-----------
<?php
if (isset($_COOKIE["uname"]))
echo "Welcome " . $_COOKIE["uname"] . "!<br />";
else
echo "You are not logged in!<br />";
?>


I always get "you are not logged in!" though. I tried on opera and IE6. And for PHP I'm using AppServ.

What is going wrong?!?! I'm pulling my hair out!

HeadBut

9:25 pm on Feb 26, 2005 (gmt 0)

10+ Year Member



Just a quick reply while I wait for a reply to my question....
First thing you want to do with any header activity is make sure your code is at the top of the page without any spaces:
<?php
cookie code...
?>
html....

no space! before the "<?php"
If php gets any space it will send the header without your cookie request..... at least thats how I understand it!

Hope that helps!

Elijah

9:31 pm on Feb 26, 2005 (gmt 0)

10+ Year Member



Also, I would make sure that you are assigning a value to $name on page one.

partha

9:44 pm on Feb 26, 2005 (gmt 0)

10+ Year Member



hooray that worked! thanks guys