File Manager
Editing: google-config.php
<?php error_reporting(E_ALL); ini_set('display_errors', 1); // Include the autoloader require_once __DIR__ . '/google-api-php-client--PHP8.3/vendor/autoload.php'; // Start the session session_start(); // Initialize the Google Client $client = new Google\Client(); $client->setClientId('326274507234-vkk75uell7rdscn81m9u779n9qtegjdt.apps.googleusercontent.com'); $client->setClientSecret('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'); $client->setRedirectUri('https://eizononline.com/google-callback.php'); $client->addScope('email'); $client->addScope('profile'); // Handle the OAuth callback if (isset($_GET['code'])) { try { // Exchange the authorization code for an access token $token = $client->fetchAccessTokenWithAuthCode($_GET['code']); $client->setAccessToken($token); // Check if the access token is valid if (array_key_exists('error', $token)) { throw new Exception(implode(', ', $token)); } // Get user info $oauth2Service = new Google\Service\Oauth2($client); $userInfo = $oauth2Service->userinfo->get(); // Extract user details $name = $userInfo->getName(); // Use this as the username $email = $userInfo->getEmail(); // Store user info in the session $_SESSION['username'] = $name; $_SESSION['email'] = $email; // Database credentials $host = "127.0.0.1:3306"; $db_username = "u404542307_dacotywebsites"; $password = "daCotywebs1te5"; $database = "u404542307_eizon"; try { // Establish database connection $pdo = new PDO("mysql:host=$host;dbname=$database", $db_username, $password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { die("Could not connect to the database: " . $e->getMessage()); } // Check if the user already exists $stmt = $pdo->prepare('SELECT * FROM users WHERE email = :email'); $stmt->execute(['email' => $email]); $user = $stmt->fetch(PDO::FETCH_ASSOC); if (!$user) { // Insert new user into the database $stmt = $pdo->prepare('INSERT INTO users (username, email, password) VALUES (:username, :email, :password)'); $stmt->execute([ 'username' => $name, // Use the name from Google as the username 'email' => $email, 'password' => '', // Leave password empty or set a placeholder ]); // Get the newly inserted user ID $userId = $pdo->lastInsertId(); // Store user ID in the session $_SESSION['user_id'] = $userId; // Redirect new users to edit_profile.php header('Location: edit_profile.php'); exit(); } else { // User already exists, get their ID $userId = $user['id']; // Store user ID in the session $_SESSION['user_id'] = $userId; // Redirect existing users to dashboard.php header('Location: dashboard.php'); exit(); } } catch (Exception $e) { echo 'An error occurred: ' . $e->getMessage(); } } ?>
💾 Save
⬅ Back