Accessibility Navigation

ImageXY

ImageXY - Mac OS X Batch Photo Resizer

Checkout ImageXY - Painless image resizing for Mac OS X.

Quickly and painlessly bulk resize images, change image formats and create web-friendly photos for your website.

Available on the Mac App Store!

Get the headers of a HTTP request with PHP

Need to check that a URL is valid? Or get the last-modified date, or the charset, or the ETag of a page? Here is a simple bit of code to help you do just that by returning the headers of a HTTP request for you.

The following PHP code is the equivalent of ‘curl -I‘:

<?php
 
$strURL = "www.webvamp.co.uk";
 
$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.


About The Author

Jacob Wyke is a web developer from the UK who makes complex things simple on the internet. He develops a batch image resizer for Mac OS X called ImageXY which you should try if you ever need to resize anything for the web.

You should also follow him on twitter.