Monday, 21 January 2019

session.cookie_domain not working as expected in Plesk / PHP application on 2 subdomains

I have 2 domains configured on the same physical server:

app.example.com
help.app.example.com

Users login to https://app.example.com/ which consists of PHP 5.5 application which stores some data in the $_SESSION array after a successful login.

I want to configure https://help.app.example.com/ so that I can read the session data present on https://app.example.com/. The application on the help subdomain is a content management system built in PHP 7.

In Plesk I have added the following to 'Additional configuration directives' for php.ini under both app.example.com and help.app.example.com:

session.cookie_domain = ".example.com"

If I upload a phpinfo() script to help.app.example.com it is showing the following for session.cookie_domain:

  • Local value: no value
  • Master value: .example.com

If I then run the following in a script on help.app.example.com:

<?php
session_start();
var_dump($_SESSION);
die;
?>

It is outputting an empty array:

array(0) { }

However, if I run the equivalent on app.example.com it is outputting an array of session data which shows details of the logged-in user (as expected):

array(15) {
   ["o_id"]=> (1) "1"
   ["u_id"]=> string(4) "1745"
   ...
}

I'm expecting to see the same output on both sub-domains. Why is this not working?

I have read Allow php sessions to carry over to subdomains but none of that resolves the problem.



from session.cookie_domain not working as expected in Plesk / PHP application on 2 subdomains

No comments:

Post a Comment