Created
October 20, 2014 20:57
-
-
Save ermand/88ed048bda6bd5fbddb4 to your computer and use it in GitHub Desktop.
Gets the HTTP status code for the given URL
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 | |
/** | |
* 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