Error request? Dns?

// my website : amalarilk.free.nf

<?php
require_once 'config.php';
session_start();

function get_client_ip() {
    $ip = 'unknown';
    if (isset($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

if (isset($_GET['code'])) {
    $code = $_GET['code'];
    $client_id = 'my clientId';
    $client_secret = 'My secret client';
    $redirect_uri = 'https://amalarilk.free.nf/discord_callback.php';

    $url = 'https://discord.com/api/oauth2/token';
    $data = [
        'client_id' => $client_id,
        'client_secret' => $client_secret,
        'grant_type' => 'authorization_code',
        'code' => $code,
        'redirect_uri' => $redirect_uri,
    ];

    // Fonction pour faire une requĂȘte POST avec cURL
    function make_post_request($url, $data) {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
        $response = curl_exec($ch);
        
        // VĂ©rifie s'il y a une erreur cURL
        if (curl_errno($ch)) {
            die('Erreur cURL: ' . curl_error($ch));
        }
        
        curl_close($ch);
        return $response;
    }

    // Faire la requĂȘte pour rĂ©cupĂ©rer le token
    $result = make_post_request($url, $data);

    if ($result === FALSE) {
        die('Erreur lors de la récupération du token');
    }

    $result = json_decode($result, true);
    if (isset($result['error'])) {
        die('Erreur dans la réponse: ' . $result['error']);
    }

    $access_token = $result['access_token'];

    // Récupérer les informations utilisateur
    $url = 'https://discord.com/api/users/@me';
    
    // Fonction pour faire une requĂȘte GET avec cURL
    function make_get_request($url, $access_token) {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $access_token]);
        $response = curl_exec($ch);
        
        // VĂ©rifie s'il y a une erreur cURL
        if (curl_errno($ch)) {
            die('Erreur cURL: ' . curl_error($ch));
        }
        
        curl_close($ch);
        return $response;
    }

    // Faire la requĂȘte pour rĂ©cupĂ©rer les informations utilisateur
    $user = make_get_request($url, $access_token);
    $user = json_decode($user, true);

    // Vérifier si la réponse utilisateur contient des données valides
    if (!isset($user['id']) || !isset($user['username'])) {
        die('Erreur lors de la récupération des informations utilisateur : ' . json_encode($user));
    }

    // Enregistrer l'utilisateur dans la base de données
    $ip_address = get_client_ip(); // RĂ©cupĂšre l'adresse IP

    $sql = "INSERT INTO users (discord_id, username, email, avatar, discriminator, ip_address) VALUES (?, ?, ?, ?, ?, ?)";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("ssssss", $user['id'], $user['username'], $user['email'], $user['avatar'], $user['discriminator'], $ip_address);
    $stmt->execute();

    $_SESSION['user_id'] = $conn->insert_id;
    header('Location: panel.php');
    exit();
} else {
    echo "Code non trouvé dans la redirection OAuth2.";
}
?>

Discord is blocked here due to abuse. Please find somewhere else to host your site.

5 Likes

I can’t find another free host

Then? You won’t be able to host your site with us, not even if you begged. Nothing will be changed on request.

And whether you can find another free hosting or not is not our business.

If you need your site so badly, consider buying hosting instead.

2 Likes

Yes, Discord is blocked on our hosting. I don’t exactly know whether we blocked Discord or Discord blocked us, but I do know that it doesn’t work.

Is there any way your website could work without the Discord integration? I get that having social logins is cool, but maybe you can find a different option.

4 Likes

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