Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sharing session across subdomains 1

Status
Not open for further replies.

jemminger

Programmer
Jun 25, 2001
3,453
US
hi all,

i'm trying to get php to share sessions across my subdomains.

the user logs in to "main.site.com", and should be allowed to visit "sub.site.com" with the same session variables intact.

per the manual, i'm setting session cookies like so:

ini_set("session.cookie_domain", ".site.com");
session_set_cookie_params(0 , '/', ".site.com");

i'm getting strange results:
if you open the browser and log in to main.site.com, sub.site.com will not share the session.

if you log out / log back in without closing the browser, the session will be shared.

anyone have experience with this?

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
after... i've got a file that's included at the top of every page that calls session_start()


-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
That's the reason why.

The PHP online manual entry for session_set_cookie_params() states:

Thus, you need to call session_set_cookie_params() for every request [red]and before session_start() is called[/red].

(emphasis mine)

I'll bet the same is true for ini_set() when you're tweaking session behavior.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top