简体   繁体   中英

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.

像这样设置cookie对我来说很好。

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

There's some problem with your path or domain name, I used this on my local and it works perfect..

<?php
setcookie("mycookie", "This cookie tastes good", time()+3600, "", "localhost");

echo $_COOKIE['mycookie'];   //output : This cookie tastes good

//refresh twice if you are setting a cookie and using echo on a same page
?>

For more info on cookie : PHP Manual

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM