Created
July 20, 2015 13:50
-
-
Save bdeleasa/02581a016f02a394a633 to your computer and use it in GitHub Desktop.
Function that checks whether the given URL exists (not a 404 page).
This file contains 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 | |
/** | |
* Figures out whether the given URL exists | |
* | |
* @param string | |
* @return bool | |
* | |
* @since 0.0.1 | |
*/ | |
function does_url_exist( $url ) { | |
$exists = false; | |
$file_headers = @get_headers($url); | |
if( $file_headers[0] === 'HTTP/1.0 404 Not Found' ){ | |
$exists = false; | |
} else if ($file_headers[0] == 'HTTP/1.0 302 Found' && $file_headers[7] == 'HTTP/1.0 404 Not Found'){ | |
$exists = false; | |
} else { | |
$exists = true; | |
} | |
return $exists; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment