1

I was using the following code to check whether a link that a user provides really points to an existing website:

$headers=get_headers($imageurl);
if (strpos($headers[0], '200') === false) {
    echo "not valid1";
    exit;
}

As test, I use the img http://cdn.thegloss.com/files/2012/04/stormtr.jpg

As long as I use this on my localhost, it works fine - i.e. it said that the url is valid and did not echo "not valid1" - now it is on a different server and it echoes "not valid1". How come? Anybody any idea?

Thanks! Dennis

Dennis Hackethal
  • 13,662
  • 12
  • 66
  • 115

2 Answers2

2

get_headers() returns false because it failed.
It might be because allow_url_fopen is set to Off on the server.

Samy Dindane
  • 17,900
  • 3
  • 40
  • 50
1

Try this it will return only the 3-digit HTTP response code

function get_response_code($theURL) {
    $headers = get_headers($theURL);
    return substr($headers[0], 9, 3);
}
Moyed Ansari
  • 8,436
  • 2
  • 36
  • 57