开发者

How can I carry cookies in php to multiple subdomain

I want to carry some cookies valu开发者_StackOverflowe 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 .


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


You're doing the correct thing (as far as I know). Refer to the PHP setcookie documentation.

domain

The domain that the cookie is available. To make the cookie available on all subdomains of example.com then you'd set it to '.example.com'.

Do you have any problems retrieving the value on the other domains?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜