Odrzucanie ciastek top-domain na subdomenie
Dodany: 12 maja, 2014 | Kategoria: Apache, PHPZałóżmy, że mamy stronę: mojadomena.pl i vip.mojadomena.pl – ale na obu jest logowanie. Ciastka z mojadomena.pl będą wtedy przesłaniać te z vip.mojadomena.pl. W PHP można jednak problem obejść:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | // fix subdomain cookies // based on from http://stackoverflow.com/a/9678857/1823945 // little changes by gnysek.pl function skip_top_level_cookies() { if (!empty($_SERVER['HTTP_COOKIE'])) { $domains_counter = array(); foreach (explode(';', $_SERVER['HTTP_COOKIE']) as $cookie_variable_string) { $key_value = explode('=', $cookie_variable_string); $cookie_var_name = trim($key_value[0]); if (!array_key_exists($cookie_var_name, $domains_counter)) { $domains_counter[$cookie_var_name] = 1; } $http_cookie_variables[$cookie_var_name][$domains_counter[$cookie_var_name]] = (!empty($key_value[1])) ? urldecode(trim($key_value[1])) : ''; $domains_counter[$cookie_var_name]++; } $levelDomain = substr_count($_SERVER['HTTP_HOST'], '.'); $newCookies = array(); foreach ($http_cookie_variables as $cookieName => $cookie) { if (array_key_exists($levelDomain, $cookie)) { $newCookies[$cookieName] = $cookie[$levelDomain]; } else { $newCookies[$cookieName] = $cookie[1]; } } $_COOKIE = $newCookies; } return true; } if (substr_count($_SERVER['HTTP_HOST'], '.') > 1) { skip_top_level_cookies(); } |