Skip to content

Instantly share code, notes, and snippets.

@bdeleasa
Created July 20, 2015 13:50
Show Gist options
  • Save bdeleasa/02581a016f02a394a633 to your computer and use it in GitHub Desktop.
Save bdeleasa/02581a016f02a394a633 to your computer and use it in GitHub Desktop.
Function that checks whether the given URL exists (not a 404 page).
<?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