title: setting cookie through curl
body: <p>I am trying to set cookie through cURL in PHP but it fails. my php code looks like this</p>
  
  <pre><code>$ch=curl_init();
  $url="http://localhost/javascript%20cookies/test_cookies.html";
  curl_setopt($ch, CURLOPT_COOKIE, 'user=1');
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $contents = curl_exec($ch);
  curl_close($ch);
  echo $contents;
  ?&gt;
  </code></pre>
  
  <p>the file test_cookies.html contains javascript that checks for a cookie and if it finds it dispalys the content with additional user content.
  but when i use the above script it displays the contents of the page test_cookies.html but not with the additional user content which means that it is not setting the cookie.</p>
  
  <p>i tried writing another script like this </p>
  
  <pre><code>&lt;?php
  header("Set-Cookie:user=1");
  header("Location:test_cookies.html");
  ?&gt;
  </code></pre>
  
  <p>this works and sets the cookie and shows the additional user content too.
  I also tried using</p>
  
  <pre><code>curl_setopt($ch,CURLOPT_COOKIEFILE,"cookie.txt");
  curl_setopt($ch,CURLOPT_COOKIEJAR,"cookie.txt");
  </code></pre>
  
  <p>this is writing the cookie information to the file but not reading it when fetching the page.
  can somebody help?</p>