PHP - 如何判断脚本在哪个域中查找cookie?

I'm trying to fix a really elusive bug where I lose my session upon redirect.

In my local setup, there is no problem; it only manifests itself on the live site. I discovered that my local version was creating two identical cookies: one for .mydomain.com and one for www.mydomain.com. However, the live site creates only one cookie for .mydomain.com.

It seems as though my script is looking for the www.mydomain.com cookie, which is why there's no apparent problem on the local server.

How do I determine to which domain a given script will look for its cookies? (or if this sounds like a different problem, please let me know)

Use setcookie(key, value, expire_time, '/') this will add cookie for your site's document root, either www.domain.com or domain.com will work fine.