<?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();
}
?>doğrulamaThis 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.