I'm currently using the following method to check if a url exists
$url = 'https://www.facebook.com/a-test-example-232397848665383511';
$headers = @get_headers($url);
if(strpos($headers[0],'200')===false){
print('NOT found!');
} else {
print('found!');
}
This prints NOT found!
even though the page clearly resolves when visited. I print the headers and found it is because it returns a 302
. Is there a way of doing a strpos
to test for all possible header values that resolve?
Current output of headers:
Array
(
[0] => HTTP/1.1 302 Found
[1] => Location: https://www.facebook.com/unsupportedbrowser
[2] => Vary: Accept-Encoding
[3] => Content-Type: text/html
// more array items
If I type in a url that i know fails I get the following:
Array
(
[0] => HTTP/1.1 404 Not Found
[1] => P3P: CP="Facebook does not have a P3P policy."
[2] => Strict-Transport-Security: max-age=15552000; preload
// rest of array
Is it safe to test simply for a 404?