Accessing session between domain/subdomain. Local xampp installation


Thanks in advance.

I have a local installation of Xampp. My sites are setup as follows. I have my main domain i.e. 'domain' installatiopn directory: C:\xampp\htdocs\domain Within this i have a subdomain setup i.e. 'subdomain.domain' installation directory: C:\xampp\htdocs\domain\subdomain

The goal of this is to have a single sign on on the main domain site and be able to access the same session data when the user accesses the subdomain site (and thus not have to re-authenticate the user once they have logged into the domain portal site).

I create the session in my domain index.php as follows:

session_set_cookie_params(0, '/', '.3pccap'); session_name('mysessionname'); session_start();

Subdomain index.php

session_name('mysessionname'); session_start();

I've added a var_dump($_SESSION); on each index.php page to confirm what session data is available. Once I log into my main domain, the session if populated with the users data. I then navigate to my subdomain site which also runs a var_dump of the session variable. The variable is displaying as an empty array.

I have attempted setting the session cookie domain within my php.ini file, no change in behaviour.

Any assistance is most appreciated.


You need to make the Session cookie visible for your subdomain (thus, calling the session_set_cookie on <strong>both</strong>, your domain and your subdomain):

session_set_cookie_params (0, '/', '.domain.com'); session_name('mysessionname'); session_start(); <hr />

EDIT (From comments, which solved the issue)

A domain hostname should consist of two parts (even for local development), e.g. domain.local instead of domain


When COOKIES are set, there is a parameter that allows you to specify the PATH and DOMAIN, if you set the DOMAIN to "domain.com" and the PATH to "/" this will make the COOKIE available accross all subdomains, some old browsers require the DOMAIN to use a leading dot(.) ".domain.com"...

<a href="http://php.net/en/set_cookie" rel="nofollow">Checkout the params on this page</a>, session_set_cookie_params also has the DOMAIN and PATH arguments


  • Override method for a collection of classes implementing an interface
  • SSL Connection timeout and read timeouts
  • Setting up ElastiCache Redis with Elastic BeanStalk + Django
  • How to execute Blackberry OS 6 app in Blackberry 10 OS
  • GDB skips over my code!
  • Can you use multiple instances of Edge on a Selenium Grid Node?
  • python & Mysql: unsupported operand type(s) for -: 'int' and 'tuple'
  • Singleton Alternative - is it equivalent?
  • Protecting critical code from being called again
  • proxy request in node.js / express
  • Installing SSL on AWS EC2 Bitnami Mean Stack
  • Symfony2 redirect to https route fails (uses wrong port)
  • Rails 3.2 from SQLite locally to Postgres on Heroku
  • XBee Linux Serial Port on Rasberry Pi
  • ASP.NET windows authentication should always ask for credentials
  • node.js POST request fails
  • CORS with socket.io
  • Authentication failed with Azure Active Directory in Windows Phone
  • Prevent Tomcat from caching request during starup
  • Access Android Market through SSH tunnel
  • How to run “Deployd” on port 80 instead of port 5000 in webserver.
  • Meteor helpers not available in Angular template
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • FB SDK and cURL: Unknown SSL protocol error in connection to graph.facebook.com:443
  • script to move all files from one location to another location
  • Upload files with Ajax and Jquery
  • Adding custom controls to a full screen movie
  • Do I've to free mysql result after storing it?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Comma separated Values
  • A cron job substitute?
  • json Serialization in asp
  • Proper way to use connect-multiparty with express.js?
  • Error creating VM instance in Google Compute Engine
  • Hits per day in Google Big Query
  • how does django model after text[] in postgresql [duplicate]
  • Busy indicator not showing up in wpf window [duplicate]
  • Conditional In-Line CSS for IE and Others?
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF