session valid in other sub-domain

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

DoppyNL

session valid in other sub-domain

Postby DoppyNL » Mon Sep 02, 2002 11:30 pm

I've got a couple of sites running on different subdomains, but the same domain.
something like this:

http://www.mydomain.com
sub1.mydomain.com
sub2.mydomain.com

When I start a session in one of those, that session is only valid in that session. How do I make the session valid for the entire "mydomain.com" domain?? so that variables in the session are available in all subdomains?

Greetz Daan

DoppyNL

Postby DoppyNL » Wed Sep 25, 2002 6:46 am

nobody got any idea??

problem should be solved when the cookie, wich the session automaticly sets, appears in every subdomain.
so if I start a session in sub1.domain.com and then go to sub2.domain.com the cookie set by the first session appears there.

Greetz Daan

DoppyNL

Postby DoppyNL » Wed Sep 25, 2002 7:28 am

Just found it out myself:

Code: Select all

$cookie_settings = session_get_cookie_params();
session_set_cookie_params ($cookie_settings['lifetime'],'/','yourdomain.com');
session_start();

This will make the session work throughout any subdomain you want.
lifetime stays the same this way.

Great monologe if I may say so myself ;) :mrgreen:

Greetz Daan


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 2 guests