Created
December 9, 2012 14:18
-
-
Save jamesrwhite/4245135 to your computer and use it in GitHub Desktop.
cURL Headers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$curl = curl_init('http://123123123123123123123123213w.com'); | |
curl_setopt_array($curl, array( | |
CURLOPT_HEADER => true, | |
CURLOPT_NOBODY => true, | |
CURLOPT_RETURNTRANSFER => true, | |
)); | |
// Get the headers | |
$headers = curl_exec($curl); | |
// Split by new lines into an array | |
$headers = explode(PHP_EOL, $headers); | |
// Remove empty lines | |
$headers = array_filter($headers, function($value) { | |
return !empty($value) and !in_array($value, array("\r", "\n")); | |
}); | |
print_r($headers); |
Weird. For me it's an empty array. I've tried from my laptop and vps as well.
May try reinstall php again, see if that solves the problem. Thanks for the help :-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Returns the following:
Array ( [0] => HTTP/1.1 200 OK [1] => Date: Sun, 09 Dec 2012 14:21:37 GMT [2] => Server: Apache [3] => Expires: Sun Dec 9 14:26:37 2012 GMT [4] => Cache-Control: private, max-age=300, must-revalidate [5] => P3P: CP="NON DSP COR DEVa PSAa PSDa OUR IND UNI COM", policyref="http://www.cnet.com/w3c/p3p.xml" [6] => Content-Type: text/html; charset=utf-8 )