What would cause sessions to not work in any subdomain but www? My login script is at http://www.mydomain.com/login.htm. When someone logs in they are shown as logged in on any page within www but as soon as they go to another subdomain such as http://aa.mydomain.com/anotherpage.htm they aren't shown as logged in anymore.
I'm using the same code on one site as on another. On one site the script works perfectly. On the other it doesn't. Any idea what could be different?
Try and use cookies...
PHP Cookies
To make the cookie available on all subdomains of example.com then you'd set it to '.example.com'. The . is not required but makes it compatible with more browsers. Setting it to www.example.com will make the cookie only available in the www subdomain. Refer to tail matching in the spec for details.
Aaron
Or keep the sessions and before each call to [man]session_start/man, use [man]session_set_cookie_params/man to set the path to '/' and the domain to something like '.mydomain.com' .
Wow Brad, I can't believe that worked. The same code is being used on another domain (obviously different cookie and session names and such though) and I dont have any problems with staying logged in for the subdomains on that domain. Who knows. Your solution worked, so thats all that matters. I spent like 4 hours last night trying to figure this out and was prepared for another long night tonight so thanks so much for the quick solution.
You can actually configure this in the root of your site.
Just make a .htaccess file (assuming you're using Apache) with something like this:
php_flag session.cookie_domain .mydomain.com