Forum Moderators: coopster

Message Too Old, No Replies

session & subdomain

         

Gruessle

7:53 am on Apr 26, 2005 (gmt 0)

10+ Year Member



If a user logs in from the main domain he has access to all subdomains; but when a user logs in from a subdomain his session is only good for that subdomain.

At Yahoo they have found something, which will work from main domains & subdomains!
I checked the session that Yahoo registers on my browser and it registered as from domain .yahoo.com with the dot before the domain.

I like that!
How do they do that?

Gruessle

8:56 am on Apr 26, 2005 (gmt 0)

10+ Year Member



Answering my own question here!
Setting the session cookie manually:
PHP Code:
session_start();
setcookie("PHPSESSID", session_id(), 0, "/", ".yoursite.com");

The first argument would be the session cookie name, usually PHPSESSID, you can check it in phpinfo(). session_id() speaks for itself, the 0 means "expire when the close the browser", the "/" maens in all directories. setting the 5th argument of the cookie to .somesite.com makes it available in all subdomains of somesite.com but not at the main domain.

So you need to add this as well:
if ($HTTP_HOST!= $SERVER_NAME) header("Location: [domain.com");...]