I am working with Cakephp and I have an issue maintaining session across subdomains. My problem is as follows:
- Users login on ‘localhost/login’
- If authenticated they are redirected to ‘customer.localhost/home’.
Currently Cake is creating a cookie for each domain ie localhost and customer.localhost.
This means that I cannot keep the session working for the user. Is there a way to make all cookies domain fixed to the parent domain with the goal of keeping the session working across subdomains?
I have tried entering this in my bootstrap but it has no effect:
ini_set(‘session.cookie_domain’, ‘.localhost’);
If you think this cannot be done please feel free to let me know so that I can move on from this frustrating problem.
Many thanks,
kSeudo
Sessions (CakePHP 2.x):
To make the session cookie valid for all your subdomains and the top level domain, you actually need to set it yourself in your
APP/config/bootstrap.phpfile:Then, in your
APP/config/core.phpfile, set Security to low:Sessions (CakePHP 3.x)
Cookies (CakePHP 2.x):
On this page it explains that you can use the ‘domain’ variable:
Per their example code:
Cookies (CakePHP 3.x):
Read here.