fork download
  1. <?php
  2. $ch = curl_init('http://www.google.com/');
  3. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4. // get headers too with this line
  5. curl_setopt($ch, CURLOPT_HEADER, 1);
  6. $result = curl_exec($ch);
  7. // get cookie
  8. // multi-cookie variant contributed by @Combuster in comments
  9. preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $result, $matches);
  10. $cookies = array();
  11. foreach($matches[1] as $item) {
  12. parse_str($item, $cookie);
  13. $cookies = array_merge($cookies, $cookie);
  14. }
  15. echo(json_encode($cookies));
  16. echo(json_encode($result));
  17. ?>
  18.  
Success #stdin #stdout 0.03s 26264KB
stdin
Standard input is empty
stdout
[]false