PHP Session Variable from subdomain to main domain

后端 未结 2 2068
鱼传尺愫
鱼传尺愫 2021-01-27 10:36

i Have setup 2 domains/sites in the ISPConfig on amazon Web server EC2 instance,

i have a domain named app.example.com and the other is https://www.example.com Both dom

2条回答
  •  长发绾君心
    2021-01-27 10:50

    The first comment of @Alan Gularte replies quite well I think. If it does not work, you may consider writing a cookie yourself to pass info back and forth.

    setcookie ("PassMySessionName", $_SESSION['user_name'], time() - 3600, "/", "example.com");
    

    Setting cookie domain to "example.com" will make it available both on www. and app.

    On the other side you will find it in the $_COOKIE array.

    $PassedUserName=$_COOKIE["PassMySessionName"];
    

    If you need it all to work without cookies enabled, it gets much more complicated, as $_SESSION will work appending parameters to your urls transparently. In that case (if you link from one site to the other) you may add them manually to the urls.

提交回复
热议问题