Search code examples
phpvalidationget-headers

Finding out whether a website returns 200


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


Solution

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