By default PHP Sessions are created per domain / sub-domain and are limited within this scope. However there are ways by which a single PHP session will be available in multiple sub-domains.
Suppose we have a domain named website.com with the following sub-domains:
All the sub-domains share the same user accounts. It would be annoying to ask the user to re-enter the login details every time he/she visits a different sub-domains. For example, Google just takes the login credentials once and then we are automatically logged in the accounts.
Any two of the following approaches can be used:
- Changing the php.ini file
- Providing the Session Cookie parameters at run-time
The dot (.) is very important to sub-domain access. Save the file reload it using the command:
For Redhat/CentOS/Fedora (as root)
service httpd reload
sudo service apache2 reload
This will effect the whole system and that’s not what you would like to see if you are running multiple sites with difference domains on the same server.
session_set_cookie_params(0, '/', '.website.com');
Try it and it should work!