7

Possible Duplicate:
PHP: Cookie domain / subdomain control
Allow php sessions to carry over to subdomains

Important Info

  • The website consists of hundreds of subdomains "example.domain.com"
  • Users logging into my site have the "remember me" feature
  • Users can login from any subdomain (and they must be able to navigate through any subdomain with that session)

Problem

  • Currently, when a user connects through one subdomain, their session/cookie (whether they chose the cookie option) isn't recognized on other subdomains.

Question

  • What must be done for a user session to be persistent across all subdomains of domain.com? In other words, I don't want a user to have to login on each subdomain.
Community
  • 1
  • 1
Adam Strudwick
  • 12,671
  • 13
  • 31
  • 41
  • 2
    Look [here](http://stackoverflow.com/questions/644920/allow-php-sessions-to-carry-over-to-subdomains?rq=1) and [here](http://stackoverflow.com/questions/348282/php-cookie-domain-subdomain-control) – jeremy Dec 29 '12 at 04:17
  • @Nile I had already tried them, and all those solutions don't work for me. As for the htaccess solution, I even get a 505 error from the server. – Adam Strudwick Dec 29 '12 at 04:30
  • For the not-working solutions: check with Wireshark what actually gets sent over the network. Also, check ALL session_ functions in the code and ALL ini_set calls in the code if they override the cookie-domain. – Skynet Dec 29 '12 at 04:36
  • Have you tried setting the `session_name` before `session_set_cookie_params`? I had that issue way back. You should also use these functions before starting the session. – Michael Dec 29 '12 at 04:48

1 Answers1

1

change the php.ini:

session.cookie_domain = domain.com

then it would be valid for all subdomains. But this depends on the all sub domais are providet by the same server.

If it are multiply servers then you have to share the session folder by NFS. Or you only add another cookie for auto login and have a seperate session for each subdomain.

http://en.php.net/manual/en/function.setcookie.php#domain

But the securrety in mind by your auto login cookie.

GreenRover
  • 1,486
  • 1
  • 14
  • 33