Alex Rivera | Logout

Allow PHP sessions to carry over to subdomains

Asked 2009-03-13T23:00:00.253
80

I use PHP sessions (not cookies, except for session id cookie) for all user data, and when a user goes to their profile user.mydomain.example they are immediately "logged out" until then remove the subdomain.

Is there a way to accept sessions from all domains as long as its *.mydomain.example

Edit
Report

1 Answer

13
        if(isset($_COOKIE['session_id']))
            session_id($_COOKIE['session_id']);
        Zend_Session::start(); //or session_start();
        if(!isset($_COOKIE['session_id']))
            setcookie('session_id', session_id(), 0, '/', '.yourdomain.example');

security be damned, if you are as frustrated with incomplete or bad answers as I am, this is your savior. It just works.

answered 2012-02-24T16:16:23.410

Your Answer