http://!@#$%^&*().com
This seems to be an invalid URL and in fact browser says its an invalid URL.
But when I fetching this URL via file_get_contents (XAMPP), it gives an exception with “500 Internal Server Error”, since this URL does not exist why am I not getting 404 ?
To check the response I’m using
$http_response_header
Here is my code:
$url = "http://!@#$%^&*().com";
$contents = @file_get_contents($url);
print_r($http_response_header);
When I run the same on another machine (WAMP), then it says $http_response_header is an undefined variable.
Anybody has got any idea what’s the problem here?
You are suppressing errors at the
file_get_contentscall, the domain you entered is actually invalid as you stated and the function call will return false and trigger the following warningYou won’t get a 404 because the domain is invalid and the http request is probably never sent, hence your
$http_response_headeris empty.Maybe a difference in OS or PHP version between XAMPP and WAMP explain why they act differently?
My advice is first checking the return value of file_get_contents and only when it’s not false continue with inspecting the response headers.