‘curl -I’ in PHP
POSTED AT 15:13 on 23rd October 2007
If you ever need to get the headers of a URL without having to download all the data then this is the code you need.
The following PHP code is the equivalent of ‘curl -I‘:
- $strURL = ‘www.redvodkajelly.com’;
- $resCurl = curl_init();
- //set URL and other appropriate options
- curl_setopt($resCurl, CURLOPT_URL, $strURL);
- curl_setopt($resCurl, CURLOPT_HEADER, true);
- curl_setopt($resCurl, CURLOPT_NOBODY, true);
- curl_setopt($resCurl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($resCurl, CURLOPT_FOLLOWLOCATION, true);
- //get the headers
- $strHeaders = curl_exec($resCurl);
- //close cURL
- curl_close($resCurl);
- echo $strHeaders;
You will of course need the cURL library compiled with PHP.


