2008年3月10日 星期一

[CakePHP]CakeSession needs support to set cookies over ALL subdomains

Description
I have a site where I need to preserve cookies over all sub-domains. Since it is quite useless to set the domain of a cookie to another domain (since browsers won't allow that) just allowing a flag to cover all subdomains might be useful.

Core...


define('CAKE_SESSION_SUBDOMAINS', true);


in cake/libs/session.php function initSession()

switch($this->security) {
case 'high':
$this->cookieLifeTime=0;
if (function_exists('ini_set')) {
ini_set('session.referer_check', $this->host);
}
break;
case 'medium':
$this->cookieLifeTime = 7 * 86400;
break;
case 'low':
default:
$this->cookieLifeTime = 788940000;
break;
}

//subdomain code
if (CAKE_SESSION_SUBDOMAINS){
if (substr_count ($this->host, ".") == 1){
cookie_domain = "." . $this->host;
}else{
$cookie_domain = preg_replace ('/^([^.])*/i', null, $this->host);
}
ini_set ("session.cookie_domain", $cookie_domain);
}
//end subdomain code


摘自:https://trac.cakephp.org/ticket/830

沒有留言:

wibiya widget