Mike L.
Mike L.

Reputation: 1966

Can a PHP Session span through sub-domains?

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

Upvotes: 1

Views: 443

Answers (4)

timdev
timdev

Reputation: 62924

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"

Upvotes: 2

stevelove
stevelove

Reputation: 3202

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

Upvotes: 1

Stoosh
Stoosh

Reputation: 2429

Check out this question.

PHP: Cookie domain / subdomain control

Upvotes: 1

jazzjazzy
jazzjazzy

Reputation: 432

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

Upvotes: 2

Related Questions