I am getting HTTP response 200 for a non-existing website

I am trying out the folowing piece of code:

<?php
$site1 = 'http://www.teraasdsfssgggdadafasfra.com.br';

$handle = curl_init($site1);
curl_setopt($handle,  CURLOPT_RETURNTRANSFER, TRUE);

/* Gets the HTML or whatever is linked in the $url. */
$response = curl_exec($handle);

/* Gets the HTTP code */
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);

echo $httpCode;

curl_close($handle);
?>

As you can see, the URL is pretty strange, which would probably return a 404 code.

However, the code I get is a 200 response, as if the page existed.

I think I might be misunderstanding the criteria that should be used to check whether a page is up or not. What might I be missing here?

Thank you.

Upvotes: 0

Views: 715

Answers (1)

brad
brad

Reputation: 1023

something like this in response to Abra http://www.google.com exists but jkshakl... will give you the 404 error you expect

<?php
    $site1 = "http://www.google.com/jkdshaklfjhdasf";

$handle = curl_init($site1);
curl_setopt($handle,  CURLOPT_RETURNTRANSFER, TRUE);

/* Gets the HTML or whatever is linked in the $url. */
if($response = curl_exec($handle)){

/* Gets the HTTP code */
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);

echo $httpCode;

curl_close($handle); 

}

else echo "server does not exist";
?>

Upvotes: 1

Related Questions