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.php
file:
ini_set('session.cookie_domain', '.domain.com');
Then, in your APP/config/core.php
file, set Security to low:
Configure::write('Security.level', 'low');
"otherwise the referer_check will be set to the current HTTP_HOST in
the CakeSession object line 441."
Sessions (CakePHP 3.x)
The session cookie path defaults to app’s base path. To change this
you can use the session.cookie_path ini value. For example if you want
your session to persist across all subdomains you can do:
Configure::write('Session', [
'defaults' => 'php',
'ini' => [
'session.cookie_path' => '/',
'session.cookie_domain' => '.yourdomain.com'
]
]);
Cookies (CakePHP 2.x):
On this page it explains that you can use the 'domain' variable:
The domain name allowed to access the cookie.
e.g. Use ‘.yourdomain.com’ to allow access from all your subdomains.
Per their example code:
<?php
public $components = array('Cookie');
public function beforeFilter() {
parent::beforeFilter();
$this->Cookie->name = 'baker_id';
$this->Cookie->time = 3600; // or '1 hour'
$this->Cookie->path = '/bakers/preferences/';
$this->Cookie->domain = 'example.com';
$this->Cookie->secure = true; // i.e. only sent if using secure HTTPS
$this->Cookie->key = 'qSI232qs*&sXOw!';
$this->Cookie->httpOnly = true;
}
Cookies (CakePHP 3.x):
Read here.
The domain that the cookie is available. To make the cookie available
on all subdomains of example.com set domain to ‘.example.com’.