1

Is there a way to make a php session span through my www.domain.com as well as sub.domain.com??? just using session_start() and $_SESSION['foo'] = "bar" does not work...any suggestions? the PHP manual does not say anything about it.

Thanks

Mike L.
  • 1,936
  • 6
  • 21
  • 37

4 Answers4

2

you can try setting the cookie domain

ini_set("session.cookie_domain", ".domain.com");

this will set all sub domains within the domain.com to be see as the one domain

jazzjazzy
  • 412
  • 3
  • 20
2

The default session tracking in PHP relies on cookies (PHPSESSID, by default, if memory serves).

You can set the domain using session_set_cookie_param() (but you must do so before calling session_start(), I think) -- or you can set it in php.ini, or .htaccess like:

php_value session.cookie_domain ".domain.com"
timdev
  • 61,857
  • 6
  • 82
  • 92
1

Check out this question.

PHP: Cookie domain / subdomain control

Community
  • 1
  • 1
Stoosh
  • 2,408
  • 2
  • 18
  • 24
1

I'm sure there are other answers, but you could use session_set_save_handler to store your sessions in a database. http://www.php.net/manual/en/function.session-set-save-handler.php

stevelove
  • 3,194
  • 1
  • 23
  • 28