I try to catch an 403 error from a file_get_contents. Please don't answer that i should use curl. Here is my code snippet:
$url = "https://authserver.mojang.com/authenticate";
$data = array(
"agent" => array(
"name" => "Minecraft",
"version" => 1
),
"username" => $username,
"password" => $password
);
$options = array(
"http" => array(
"header" => "Content-Type: application/json\n",
"method" => "POST",
"content" => json_encode( $data )
)
);
$context = stream_context_create( $options );
$result = file_get_contents( $url, false, $context );
$response = json_decode( $result );
My problem is, when i do a request with valid credentials, mojang answer with a valid json string. But when i do a request with invalid credentials i get an 403 HTTP error.
How can i catch them without a warning on my site.