Skip to content

Instantly share code, notes, and snippets.

@ermand
Created October 20, 2014 20:57
Show Gist options
  • Save ermand/88ed048bda6bd5fbddb4 to your computer and use it in GitHub Desktop.
Save ermand/88ed048bda6bd5fbddb4 to your computer and use it in GitHub Desktop.
Gets the HTTP status code for the given URL
<?php
/**
* Gets the HTTP status code for the given URL.
*
* @param string $url The URL to check.
* @return int
*/
function url_http_status($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $status;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment