title: Save cookies for remote web pages
body: <p>I've got a PHP application which needs to grab the contents from another web page, and the web page I'm reading needs a cookie.</p>
  
  <p>I've found info on how to make this call once i have the cookie ( <a href="http://groups.google.com/group/comp.lang.php/msg/4f618114ab15ae2a" rel="nofollow noreferrer">http://groups.google.com/group/comp.lang.php/msg/4f618114ab15ae2a</a> ), however I've no idea how to generate the cookie, or how / where the cookie is saved.</p>
  
  <p>For example, to read this web page via wget I do the following:</p>
  
  <pre><code>wget --quiet --save-cookies cookie.file --output-document=who.cares \ 
    http://remoteServer/login.php?user=xxx&amp;pass=yyy
  
  wget --quiet --load-cookies cookie.file --output-document=documentiwant.html \
    http://remoteServer/pageicareabout.html
  </code></pre>
  
  <p>... my question is how do I do the '--save-cookies' bit in PHP so that I can use the cookie in the follow-up PHP stream_context_create / file_get_contents block:</p>
  
  <pre><code>$opts = array(http'=&gt; array(
    'method'=&gt; "GET",
    'header'=&gt;
      "Accept-language: en\r\n" .
      "Cookie: **NoClueAtAll**\r\n"
    )
  );
  
  $context = stream_context_create($opts);
  $documentiwant = file_get_contents("http://remoteServer/pageicareabout.html",
    0, $context);
  </code></pre>