mingfish_004
mingfish_004

Reputation: 1413

how to get a common cookie value in deferent sites?

I have a cookie
cookie_name : debug_flag
cookie_value: 1
cookie_domain : localhost

I have 2 sites with diffrent domain:
www.aaa.com
www.bbb.com

I want to get the common cookie (debug_flag) in these sites using php.
how can I get it?

<?php 
    // how to get debug cookie ....
    if($debug_flag){
        echo 'yes'
    }
?>

Upvotes: 0

Views: 57

Answers (1)

Alma Do
Alma Do

Reputation: 37365

You can not. Cookies are used inside domain only (2-nd level domain) and can not be passed natively (i.e. via cookie logic in browser) from one domain to another. You have to pass your variable via another way, such as GET, for example. Another way is to make your sites (I assume they are both yours) as a subdomains for common domain, i.e.

aaa.domain.com
bbb.domain.com

-then you will be able to access cookies from one site to another.

Cookie are used per domain for security reason - so to be sure that one site will never access to cookies of another.

Upvotes: 2

Related Questions