Home>
Problem

I want to create a login button with discord on my site, but I get an Invalid \ "redirect_uri \" in request.
The redirect url has already been registered on the Discord Developer page.

I googled on the internet, but I didn't understand the cause.

Program

<? php
$redirect_url = 'https://bot.midokuriserver.com/webdashboard/setlogin.php';
$code = $_GET ["code"];
$url = 'https://discordapp.com/api/oauth2/token';
// Data to send POST
$data = array (
    'client_id' =>'client id',
    'client_secret' =>'client secret',
    'grant_type' =>'authorization_code',
    'code' =>$code,
    'redirect_url' =>$redirect_url,
    'scope' =>'identify'
);
// URL encoding
$data = http_build_query ($data, "", "&");
// Options when sending
$options = array ('http' =>array (
    'method' =>'POST',
    'content' =>$data,
    'protocol_version' =>'1.1',
    'ignore_errors' =>true
));
// create a stream context
$options = stream_context_create ($options);
// file_get_contents
$contents = file_get_contents ($url, false, $options);
// output
echo $contents;
?>