RedVodkaJelly Logo

‘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‘:

  1. $strURL = ‘www.redvodkajelly.com’;
  2. $resCurl = curl_init();
  3. //set URL and other appropriate options
  4. curl_setopt($resCurl, CURLOPT_URL, $strURL);
  5. curl_setopt($resCurl, CURLOPT_HEADER, true);
  6. curl_setopt($resCurl, CURLOPT_NOBODY, true);
  7. curl_setopt($resCurl, CURLOPT_RETURNTRANSFER, true);
  8. curl_setopt($resCurl, CURLOPT_FOLLOWLOCATION, true);
  9. //get the headers
  10. $strHeaders = curl_exec($resCurl);
  11. //close cURL
  12. curl_close($resCurl);
  13. echo $strHeaders;

You will of course need the cURL library compiled with PHP.


Leave a Comment