-1

I am trying to use session data on subdomains.

EX:

www.mywebsite.com

test.mywebsite.com

When I try to use session data from www.mywebsite.com to subdomain, all the session information is not accessible.

Set session

public function homeAction($value='')
{
    $domain = eregi_replace('^WWW', '', "$_SERVER[HTTP_HOST]");
    $subdomain = substr($domain,0);

    $request = $this->getRequest()->getHeaders()->get('Set-Cookie')->foo = 'bar';
    $response = $this->getResponse()->getCookie()->baz = 'test';


    $userSession = new Container('userinfo');
    $userSession->email = 'admin@admin.in'; // write session 
    $userSession->password = 'e10adc3949ba59abbe56e057f20f883eaa';

    $dmn_link = 'http://app'    . $subdomain . '/auth';
    $www_link = 'http://www' . $domain . '/career';

    echo "<br/><a target=\"_blank\" href=\"$www_link\">$www_link</a>\n";
    echo "<br/><a target=\"_blank\" href=\"$dmn_link\">$dmn_link</a>\n";


    echo "<pre>";

    print_r($_COOKIE);

    print_r($_SESSION);
}

Print Session in same Domain in home page HomeAction

Array
(
    [PHPSESSID] => pgguqil2e87h0hn3risov330m3
    [_ga] => GA1.2.1895217383.1504264473
    [_gid] => GA1.2.1845702714.1504264473
    [__zlcmid] => iIgiLC7vUKt6CC
)
Array
(
    [__ZF] => Array
        (
            [_REQUEST_ACCESS_TIME] => 1504271027.5384
        )

    [userinfo] => Zend\Stdlib\ArrayObject Object
        (
            [storage:protected] => Array
                (
                    [email] => admin@admin.in
                    [password] => e10adc3949ba59abbe56e057f20f883eaa
                )

            [flag:protected] => 2
            [iteratorClass:protected] => ArrayIterator
            [protectedProperties:protected] => Array
                (
                    [0] => storage
                    [1] => flag
                    [2] => iteratorClass
                    [3] => protectedProperties
                )

        )

)

when am trying to use data on subdomain am not able to get session data

susheel sahoo
  • 107
  • 2
  • 8
  • 1
    The function `eregi_replace()` deprecated since php v5.3 and removed as of PHP 7.0. Please stop using it. https://secure.php.net/manual/en/function.eregi-replace.php – edigu Sep 03 '17 at 14:59

1 Answers1

1

You should consider to use cookies or include parameter into url for other domain.

for your ref. see here Cross-Domain Cookies

and Cross domain PHP Sessions

this might be helpful: Secure and Flexible Cross-Domain Sessions

Gautam Rai
  • 2,445
  • 2
  • 21
  • 31