Search code examples
phpcookiesdnssubdomain

I Need Create Cookie On Domain And Get It On subdomain


I'm with an difficult to create cookie an domain and use it another subdomain.

I'm trying set cookie whith this code:

ini_set("session.cookie_domain", "mydomain.com.br");

setcookie("test", "test_value", time()+3600);

And get cookie whith this code on my subdomain(subdomain.mydomain.com.br):

echo "<pre>";
print_r($_COOKIE);
print_r($_SERVER ['HTTP_COOKIE']);
die("</pre>"); 

What I did wrong? rs


Solution

  • I use this:

    setcookie();
    setcookie("test","test_value",time()+3600,'/','.mydomain.com.br');