tags:

views:

21

answers:

1

hey guys, 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 same 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?

A: 

$_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');
Matchu
thank you will try that!
where do i have to set that? just right after the session_start(); ?
@mathiregister - I've never used it; I only found it in the PHP docs by Googling. I'd bet you would put it *before* `session_start`, so that the session starts with the correct settings. Some browsers and extensions will allow you to inspect your cookies in detail - that might help for debugging this particular bit.
Matchu
do happen to know if session_set_cookie_params() also works for the set_cookie() method? or do i have to use sessions?
@mathiregister - [see the manual page on setcookie](http://php.net/setcookie) - if you want those options, use the optional arguments on `setcookie`.
Matchu