Misafir adlı üyeden alıntı: mesajı görüntüle
<?php
require 'vendor/autoload.php';
 
use Github\Client;
 
session_start();
 
$githubClientId = 'xxxxxxx';
$githubClientSecret = 'xxxxxx';
$redirectUri = 'http://xx.xx.xx.xx/githublogin.php';

$client = new Client();
 
try {
    if (isset($_GET['code'])) {
        // GitHub'tan gelen code parametresini kullanarak token al
        $token = $client->authenticate($githubClientId, $githubClientSecret, $_GET['code']);

        // Kullanıcı bilgilerini al
        $userInfo = $client->api('current_user')->show();
        $githubUsername = $userInfo['login'];
        $githubEmail = $userInfo['email'];
        $githubAvatarUrl = $userInfo['avatar_url'];

        // Kullanıcı bilgilerini session'a kaydet
        $_SESSION['github_username'] = $githubUsername;
        $_SESSION['github_email'] = $githubEmail;
        $_SESSION['avatar_url'] = $githubAvatarUrl;

        // Kullanıcı bilgilerini veritabanına kaydet
        // Bu kısmı istediğiniz şekilde veritabanınıza uygun şekilde düzenleyin
        $servername = "localhost";
        $username = "kullanici_adi";
        $password = "sifre";
        $dbname = "veritabani_adi";

        $conn = new mysqli($servername, $username, $password, $dbname);

        if ($conn->connect_error) {
            die("Bağlantı hatası: " . $conn->connect_error);
        }

        $sql = "INSERT INTO kullanici_tablosu (github_username, github_email, avatar_url) VALUES ('$githubUsername', '$githubEmail', '$githubAvatarUrl')";

        if ($conn->query($sql) === TRUE) {
            echo "Kullanıcı bilgileri başarıyla veritabanına eklendi";
        } else {
            echo "Hata: " . $sql . "<br>" . $conn->error;
        }

        $conn->close();

        // Başarıyla işlem yapıldıktan sonra ana sayfaya yönlendir
        header('Location: ana_sayfa.php');
        exit;
    } else {
        // GitHub OAuth sayfasına yönlendir
        $oauthUrl = $client->getAuthorizationUrl($githubClientId, $redirectUri, ['user']);
        header('Location: ' . $oauthUrl);
        exit;
    }
} catch (\Exception $e) {
    echo 'Hata: ' . $e->getMessage();
}
?>
<?php
require 'vendor/autoload.php';
use Github\Client;
session_start();
$githubClientId = 'xxx;
$githubClientSecret = 'xxx';
$redirectUri = 'http://xx.x.xx.xxx/profile.php';
$client = new Client();
try {
    if (isset($_GET['code'])) {
        // GitHub'tan gelen code parametresini kullanarak token al
        $token = $client->authenticate($githubClientId, $githubClientSecret, $_GET['code']);
        // Kullanıcı bilgilerini al
        $userInfo = $client->api('current_user')->show();
        $githubUsername = $userInfo['login'];
        $githubEmail = $userInfo['email'];
        $githubAvatarUrl = $userInfo['avatar_url'];
        // Kullanıcı bilgilerini session'a kaydet
        $_SESSION['github_username'] = $githubUsername;
        $_SESSION['github_email'] = $githubEmail;
        $_SESSION['avatar_url'] = $githubAvatarUrl;
        // Kullanıcı bilgilerini veritabanına kaydet
        // Bu kısmı istediğiniz şekilde veritabanınıza uygun şekilde düzenleyin
        // PostgreSQL veritabanına bağlanma
$conn = pg_connect("host=xx.xx.xx.xx port=5432 dbname=xx user=xx password=xxxxx");
        if (!$conn) {
            die("Bağlantı hatası: " . $conn->connect_error);
        }
                $insertUserQuery = "INSERT INTO kullanicilar (kullanici_adi, mail,photourl) VALUES ($1, $2, $3)";
                $params = array($githubUsername, $githubEmail,$githubAvatarUrl);
                $insertUserResult = pg_query_params($conn, $insertUserQuery, $params);
        $conn->close();
        // Başarıyla işlem yapıldıktan sonra ana sayfaya yönlendir
        header('Location: profile.php');
        exit;
    } else {
        // GitHub OAuth sayfasına yönlendir
        $oauthUrl = $client->getAuthorizationUrl($githubClientId, $redirectUri, ['user']);
        header('Location: ' . $oauthUrl);
        exit;
    }
} catch (\Exception $e) {
    echo 'Hata: ' . $e->getMessage();
}
?>

github doğrulama

This page isn’t working


xx.xx.xx.xxx is currently unable to handle this request.
HTTP ERROR 500 hatası veriyor. bu hatayı github giriş kısmına erişemediğinde veriyordu.