title: How to use file_get_contents() with a Wordpress user's cookies
body: <p>I need to send a <code>file_get_contents()</code> to an API endpoint with the client's cookies that are set by Wordpress to show that the user is logged into the wordpress site. I know I need to use <code>stream_context_create()</code> roughly as follows:</p>
  
  <pre><code>$cookies = ??? //THIS IS THE QUESTION (see answer below)!
  
  // Create a stream
  $opts = array(
    'http'=&gt;array(
      'method'=&gt;"GET",
      'header'=&gt;"Accept-language: en\r\n" .
                "Cookie: {$cookies}\r\n"
    )
  );
  
  $context = stream_context_create($opts);
  
  // Open the file using the HTTP headers set above
  $file = file_get_contents('http://example.dev/api/autho/', false, $context);
  </code></pre>
  
  <p>As you can see from the comment on the first line, I'm stuck on how to send this request so that the correct cookies are sent. I know the correct cookies are sent because I can print out <code>$_COOKIES</code> and see them there. But if I try to insert that same array into the headers, it doesn't work.</p>
  
  <p>Thanks in advance!</p>
  
  <p>ps: I've read that I should use <code>cURL</code> for this, but I'm not sure why and I don't know how to use it... but I'm open to the idea.</p>
  
  <p>UPDATE:
  I got this to work. It's basically the same thing I was doing, with another important cookie . See my answer below.</p>