Search code examples
phpsetcookie

setcookie() doesn't work properly?


Hi I'm trying to use cookies on my site. I created two test pages to try them out before I implement them in my site, but it doesn't seem to work well.

page one has:

<?php
setcookie("apple", "abc", time()+1500, "/", "b****a.org");
?>

page two has:

<?php
echo $_COOKIE["apple"];
?>

So to test it, I go to page one first, then I go to page two. For some reason, page two just outputs the letter "b" on the screen. That's it. I tried it on another computer, and it outputs "abcb" what's this b for? I'm guessing the cookie isn't getting stored on my computer, but it does work on two other computers so I guess it's just my problem. Anyways, why does it output an extra "b" at the end?

Thanks.


Solution

  • Setting the cookie like this worked fine for me.

    setcookie("apple", "abc", time()+1500);