SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    cross domain cookie

    Code:
    <?php
    setcookie("myCookie", 1, time() +50);
    echo $myCookie."<br>";
    ?>
    
    <!doctype html> 
    <html>   
      <head> 
        <meta charset="UTF-8"> 
        <title>crossDomainCookie</title> 
      </head> 
    <body>
    
    <a href="http://dot.kr/x-test/crossDomainCookie.php">dot.kr</a><br>
    <a href="http://www.dot.kr/x-test/crossDomainCookie.php">www.dot.kr</a><br>
    <a href="http://subDomain2.dot.kr/x-test/crossDomainCookie.php">subDomain2.dot.kr</a><br>
    <a href="http://term.kr/x-test/crossDomainCookie.php">term.kr</a><br>
    
    </body> 
    </html>
    The 4 links in the code above opens a same file.
    But the cookie value doesn't show when it clicks the link crossing the domain.

    Is there anyway for making the cookie( or session or other global variables ) to work cross domain?

    You can test it in http://dot.kr/x-test/crossDomainCookie.php

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    No, cookies can never be cross domain.
    They can only exist in the same root domain (.root.tld [tld: com, net, org, etc]) and above

    http://us.php.net/setcookie
    domain

    The domain that the cookie is available to. To make the cookie available on all subdomains of example.com (including example.com itself) then you'd set it to '.example.com'. Although some browsers will accept cookies without the initial ., RFC 2109 requires it to be included. Setting the domain to 'www.example.com' or '.www.example.com' will make the cookie only available in the www subdomain.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •