File Manager
Editing: google-callback.php
<?php require_once 'google-config.php'; // Check if the authorization code is present if (isset($_GET['code'])) { try { // Exchange the authorization code for an access token $token = $client->fetchAccessTokenWithAuthCode($_GET['code']); // Check if the token exchange was successful if (array_key_exists('error', $token)) { throw new Exception('Token exchange failed: ' . $token['error']); } // Ensure the access token is set if (!isset($token['access_token'])) { throw new Exception('Access token not found in the response.'); } // Set the access token in the client $client->setAccessToken($token['access_token']); // Get user profile info $google_oauth = new Google_Service_Oauth2($client); $google_account_info = $google_oauth->userinfo->get(); $email = $google_account_info->email; $name = $google_account_info->name; // TODO: Add user to your database or start a session // Example: Redirect to the dashboard after successful login header('Location: dashboard.php'); exit(); } catch (Exception $e) { // Log the error and redirect to the register page error_log('Google OAuth Error: ' . $e->getMessage()); header('Location: register.php'); exit(); } } else { // Redirect to the register page if no authorization code is found header('Location: register.php'); exit(); } ?>
💾 Save
⬅ Back