views:

157

answers:

2

I want to carry some cookies value to different subdomains like

blog.mydomain.com , profile.mydomain.com , stats.mydomain.com, etc.

Right now I am using below code to set cookies

setcookie('var_name', 'var_value', null, "/", '.mydomain.com' );

With this code, cookies set on blog.mydomain.com available on mydomain.com but not on other subdomain (profile.mydomain.com , stats.mydomain.com, etc.)

Please, let me know, whats wrong with my code .

+1  A: 
The Pixel Developer
thanks for your reply, its my mistake in testing. I deleted all cache , cookies, and restarted browser and it's working now. Sorry for taking your precious time
santosh
+2  A: 

try:

$res = setcookie('var_name', 'var_value', null, "/", '.mydomain.com' );
var_dump($res); exit;

the output should be TRUE, if you see false it means output exists prior to calling this function and you can't set cookies after beginning sending content

mathroc
thanks for your reply, its my mistake in testing. I deleted all cache , cookies, and restarted browser and it's working now. Sorry for taking your precious time
santosh