Error while using file_get_contents

$context = stream_context_create(array(
    "http" => array(
        "header" => "Authorization:Bot XXXXXX\r\n"
    )
));
$response = file_get_contents("https://discordapp.com/api/users/" . $id, false, $context);

file_get_contents(https://discordapp.com/api/users/XXXXXX): failed to open stream: Connection timed out

It works locally, but not on my website, can you help me please?

This means the access to the Discord API is blocked. Most of the time, this happens because of a high abuse rate of a particular API, for example for spam bots.

We have the responsibility to stop abuse on our service, but we don’t have the capabilities to review every website and application using high risk APIs by hand on free hosting.

So, in short, you can’t use the Discord API on free hosting. If you want to use this API, you could consider to switch to iFastNet Premium Hosting, where (to my knowledge), no APIs are being blocked.

Thanks for the answer, but as I said, it works perfectly in local. Also, the Authorization header is there to prevent blocking, so I think that don’t come from it or my code :confused:

I’m sorry, but I don’t believe I said it was caused by your own code.

It doesn’t work because we blocked access to that API. That’s not caused by your code or configuration. It works fine on your own computer, because you haven’t blocked access to the Discord API on the system level.

Ok, thanks, I’ll try to find a service for this with your advices :smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.