开发者

AJAX & PHP: load foreign domain via proxy and use session cookie?

i wonder if i'm doing anything wrong or I am just getting this wrong?

I'm loading a part of a of subdomain with jquery load(). just before i'm firing the load method i'm saving a password to a $_SESSION with php. The part of the subdomain i'm loading with jquery load() needs this password information.

Does this count as the 开发者_如何学Csame session, because I can't retrieve the $_SESSION information inside my loaded subdomain part?

Or isn't this working because I'm actually loading a part of DIFFERENT website so the session is a different one?

any idea?


$_SESSION is tied to a cookie named PHPSESSID, which is by default available only to the exact domain name where you use it. a.example.com can't access cookies from b.example.com, and so the sessions can't cross over, either.

There is, however, a way to set the PHPSESSID cookie to be available across your entire domain: session_set_cookie_params() allows you to apply relevant settings to that PHPSESSID cookie. By setting the domain to .example.com (the dot at the front must be there!), you make the cookie available to example.com and all subdomains.

session_set_cookie_params(0, '/', '.example.com');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜