php - Can't make cookies work for subdomain -


update: looks didn't work because of local machine hosting, particularly short domain names used (like '.t'). same code on remote server actual (real-life) domain names usage works fine.

there 2 domains (the root , it's sub one) both running looking @ same webserver's directory, thus, working on exact same scripts. (i have apache/php run on windows xp on home computer, choose use short names local hosts - 't' , 'a.t' respectively).

session_set_cookie_params(           24*3600, // 24 hours            '/',     // paths           '.t',    // 't' , sub-domains           false,   // not secure           false    // not http-only      );   session_start();  if ($_server['http_host'] == 't')      setcookie(             'test',           // cookie name             'yes',            // cookie value             time() + 24*3600, // expires after 24 hours             '/',              // paths             '.t',             // t , subdomains             false,            // not secure             false             // not http-only         );  echo $_server['http_host'] . '<br>';  print_r($_cookie); 

here have root local host:

t  array ( [phpsessid] => 23lhahncni8ekeqj3j02u7qlq5 [test] => yes ) 

and subdomain:

a.t  array ( ) 

as can see, $_cookie array subdomain empty, although corresponding cookies can seen browser (firebug, exact - can see 2 cookies in tab subdomain's page opened). can't figure out why happening.

i need access $_cookie[test] both domains. how can accomplish that?

you need specify domain in call setcookie():

setcookie('test', 'yes', 0, '/', '.t'); 

session_set_cookie_params() sets options cookie used save $_session, not cookies set using setcookie.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -