title: how to get cookies from a different domain with php and javascript
body: <p>Suppose i have a cookie set in first.com say user. Now i want to read that cookie in second.com through javascript and ajax. But it is not working.I have got xmlHttp.status=0.</p>
  
  <p>sample code</p>
  
  <p>in the second domain readcookie.php file</p>
  
  <pre><code>var xmlHttp;
      function createXMLHttpRequest(){
          if(window.ActiveXObject)
              xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          if(window.XMLHttpRequest)
              xmlHttp=new XMLHttpRequest();
      }
      function readcookie(){
  
          createXMLHttpRequest(); 
          xmlHttp.open("GET","http://www.first.com/cookie.php",true);
          xmlHttp.onreadystatechange=getcookie;
          xmlHttp.send(null);
      }
      function getcookie(){
          if(xmlHttp.readyState==4){
              if(xmlHttp.status==200){
                  var reply=xmlHttp.responseText;
                  if(reply){
                      alert(reply);
                  }
              }
              else
                  alert(xmlHttp.status);
          }
      }
  </code></pre>
  
  <p>in the first domain cookie.php file</p>
  
  <pre><code>if(isset($_COOKIE['user'])){
          echo $_COOKIE['user'];
      }
      else{
          setcookie('user','a2345',0);
          echo $_COOKIE['user'];
      }
  </code></pre>