Jump to content


Carrying sessions across subdomains


8 replies to this topic

#1 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 19 August 2006 - 07:06 PM

Ok so - I have a dilemma - I need to carry across my session values throughout subdomains. I also need it so when I destroy a session it destroys all the sessions amongst my subdomains.

Just to clarify if I set $_SESSION['name'] = 'George'; on domain.com I want to be able to access $_SESSION['name']; on name.domain.com

I search Google and several people had things they claimed worked but from what i've tried nothing seems to work.

	session_id();
	session_set_cookie_params(3600);
	session_start();

That was one method someone suggested but it didn't work - anyone have any insight?

Edited by Lang, 19 August 2006 - 07:06 PM.


#2 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 19 August 2006 - 07:26 PM

Try this in your .htaccess if you haven't already:

php_value session.cookie_domain .domain.tld

I could be wrong but im sure there is a reason why this cant be done achually :S

Edited by .Matt, 19 August 2006 - 07:28 PM.


#3 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 19 August 2006 - 07:30 PM

View Post.Matt, on Aug 19 2006, 08:25 PM, said:

Try this in your .htaccess if you haven't already:

php_value session.cookie_domain .domain.tld

I could be wrong but im sure there is a reason why this cant be done achually :S

Do I change domain.tld to my domain? And do I put this in the .htaccess in all my subdomains and my top-level?

[EDIT] That line caused a 500 error (Internal Server Error)

Edited by Lang, 19 August 2006 - 07:33 PM.


#4 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 19 August 2006 - 07:45 PM

ok, repost, (forget the above) looked into the function you mentioned above, never used it before but try:

session_set_cookie_params(3600, '/', '.domain.com');

unsure what a time parameter is doing with sessions but meh. (call it before session_start())

#5 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 19 August 2006 - 07:54 PM

Yeah I did try that before. But no matter - I figured out how to do it :huh: I just had to scour the PHP Manual for that function PHP.net doesn't want you to find because it helps people take over the world. (not really)

ini_set("session.cookie_domain", '.firewhiskey.net');

#6 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 19 August 2006 - 07:55 PM

lol. Sod it i was gonna suggest that but it came up so much in google that i thought you must have tried it rofl. :huh:

#7 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 20 August 2006 - 12:44 AM

View Post.Matt, on Aug 20 2006, 12:25 AM, said:

Try this in your .htaccess if you haven't already:

php_value session.cookie_domain .domain.tld

I could be wrong but im sure there is a reason why this cant be done achually :S


View PostLang, on Aug 20 2006, 12:53 AM, said:

Yeah I did try that before. But no matter - I figured out how to do it :D I just had to scour the PHP Manual for that function PHP.net doesn't want you to find because it helps people take over the world. (not really)

ini_set("session.cookie_domain", '.firewhiskey.net');

Aren't those the same thing? :P

Just one looks like it's formated to go in the PHP.INI and the other in .htaccess

#8 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 20 August 2006 - 06:50 AM

They are yes and if i had given the correct line to go in htaccess in the first place it would have worked. :P

#9 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 20 August 2006 - 10:57 AM

By correct value, you mean "php_flags" right? Either way, some host's don't allow you to modify the php.ini file via htaccess, so it could have still thrown a 500 error.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users