views:

21

answers:

1

I'm currently using file_get_contents() to fetch the contents of a page which is sort of like an Authentication API. It works great for the default system which most people use (which just uses the default HTTP/1.1 200 status code), but some people send relevant HTTP status codes for different errors. For example 401 PASSWORD_FAIL, in which case it would set the HTTP status to 401 and output 'PASSWORD_FAIL' to the page, which is the part I want to get. But the 401 status code causes file_get_contents() to error out and not do anything. What is the simplest PHP function I can use to get the contents of the page and just ignore the HTTP status code?

+2  A: 
$opts = array('http' =>
    array(
        'ignore_errors'  => true,
    )
);

$context  = stream_context_create($opts);
$result = file_get_contents($url, false, $context);

See the manual on the http wrapper context options.

Artefacto