简体   繁体   中英

Bluehost (or PHP Script) Issue With Cookies

I've got the weirdest problem with Cookies. I've written some PHP script that uses tokens to identify the visitor so that "he/she" can use the website correctly.

The Token system is working perfectly on the local development machine (windoze+ZendApache) and doesn't work on the production server, which is on Bluehost.

I use "/" for path and "mydomain.com" for the domain when setting the cookie with an expiry of 60 days. I can see the cookies on the browser correctly and I can confirm that the values are set correctly when compared to the values in the database.

Every time the page gets refreshed the server doesn't get the cookie and creates a new token and sends it back to the browser and is creating a new record in the database again. The new cookie matches the latest record again, but next time I refresh, same thing all over again. Can't maintain the token, so navigating the site is impossible.

Any idea why this is happening? Is it possible that I've missed some setting?

I've tested it on latest Firefox, Opera, Safari and Chrome.

Thanks.

EDIT:

It is a PHP & Bluehost related issue, I was storing 3, 40-character strings on the value of the cookie in serialized format. The unserialize() function wasn't executing for some reason on Bluehost but was running fine on my dev machine. So I changed the stored value to 40chars.40chars.40chars and exploded the value with the delimiter "." to get the 3 strings.

Thanks again.

you should use

.mydomain.com

instead of

mydomain.com

for example:

setcookie("MyCookie", $value, time()+60*24*3600, "/", ".mydomain.com", 1);

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