1

I have domains like:

  • www.domain.com
  • countyName1.domain.com
  • countryName2.domain.com

All these domains are using the same directory files /public_html. I want to share session among all these domains.

I already tried these:

ini_set('session.cookie_domain', '.example.com' );
session_start();

OR

$some_name = session_name("some_name");
session_set_cookie_params(0, '/', '.some_domain.com',false,false);
session_start();

But none of them seems to be working for me.

Many Thanks.

Kumari Manisha
  • 682
  • 2
  • 8
  • 22
  • 1
    Possible duplicate of [Preserving session variables across different domains](http://stackoverflow.com/questions/14611545/preserving-session-variables-across-different-domains) – Florian Humblot May 09 '17 at 08:27
  • @FMashiro Hi, i have the same domain name – Kumari Manisha May 09 '17 at 08:31
  • can you try to make two files, with the same code: `ini_set('session.cookie_domain', '.example.com' ); session_start();` and then `var_dump($_SESSION);` to see what is actually inside of the session? – Florian Humblot May 09 '17 at 08:38
  • No. I have not used two files. Because i need to share session among all domain, whether session created from first domain or second or third. But, i used something like this `if(isset($_SESSION['id'])){ var_dump($_SESSION); }else{ ini_set('session.cookie_domain', '.domain.com' ); }` – Kumari Manisha May 09 '17 at 08:58
  • ok, try making a file "test.php" that is accessible on the sites. In that file, put this code: `ini_set('session.cookie_domain', '.example.com' ); session_start(); var_dump($_SESSION); die();` Now, go to www.domain.com/test.php and countyName1.domain.com/test,php and show us what you get on both sites – Florian Humblot May 09 '17 at 09:00
  • in logged-in domain i.e 'www.domain.com', I got this: `array(16) { ["start"]=> int(1494320622) ["id"]=> int(97) ["Error_msg"]=> string(0) "" ["logged"]=> int(1) ["first_name"]=> string(6) "kumari" ["last_name"]=> string(7) "manisha" ["active"]=> string(1) "1" ["blocked"]=> int(1) ["verified"]=> string(1) "1" ["mobile_verified"]=> int(1) ["account_disable"]=> int(0) ["userImage"]=> int(578) ["cid"]=> int(97) ["entity"]=> int(1) ["viewMode"]=> string(1) "0" }` While for other subdomain I am getting `array(2) { ["start"]=> int(1494320056) ["id"]=> NULL}` – Kumari Manisha May 09 '17 at 09:08
  • have you tried the second approach without the last two arguments? – Florian Humblot May 09 '17 at 09:17
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/143758/discussion-between-fmashiro-and-kumari-manisha). – Florian Humblot May 09 '17 at 09:17

0 Answers0