title: Trying to get request header cookies and response cookie
body: <p>I'm trying to send build my API, but I have to login first.
  When I hit login, there's response header and request header. They set cookies, as shown in pictures. 
  How could I get these cookies into a variable to use it in other file or something like that?</p>
  
  <p><a href="https://i.stack.imgur.com/zo8p1.png" rel="nofollow noreferrer">reqested header</a>
  <a href="https://i.stack.imgur.com/oGjSB.png" rel="nofollow noreferrer">responed header</a></p>
  
  <p>my code</p>
  
  <pre><code>$file = 'cookies.txt';
  $buffer = "__RequestVerificationToken=$ver;";
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, "http://www.xxxx.org/L/DoLogin");
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0');
  curl_setopt($ch, CURLOPT_HEADER  ,array("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"));
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, "__RequestVerificationToken=$buffer&amp;username=xxxx&amp;pw=xxxx&amp;rememberMe=true&amp;loginAcc=");
  
  curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  $content = curl_exec($ch);
  
  // get cookies
  $cookies = array();
  preg_match_all('/Set-Cookie:(?&lt;cookie&gt;\s{0,}.*)$/im', $content, $cookies);
  
  print_r($cookies['cookie']); // show harvested cookies
  
  // basic parsing of cookie strings (just an example)
  $cookieParts = array();
  preg_match_all('/Set-Cookie:\s{0,}(?P&lt;name&gt;[^=]*)=(?P&lt;value&gt;[^;]*).*?expires=(?P&lt;expires&gt;[^;]*).*?path=(?P&lt;path&gt;[^;]*).*?domain=(?P&lt;domain&gt;[^\s;]*).*?$/im', $content, $cookieParts);
  print_r($cookieParts);
  </code></pre>