Reputation: 41
I am trying to login with google api for php and then redirect the user to the dashboard.php but suddenly this error occurred during the redirection my files: the callback file that is responsible for tokens and redirection to dashboard.php
<?php
session_start();
require_once("../gog.php");
if (isset($_SESSION['access_token']))
$gClient->setAccessToken($_SESSION['access_token']);
else if (isset($_GET['code'])) {
$token = $gClient->fetchAccessTokenWithAuthCode($_GET['code']);
$_SESSION['access_token'] = $token;
} else {
header('Location:../index.php');
exit();
}
$oAuth = new Google_Service_Oauth2($gClient);
$userData = $oAuth->userinfo_v2_me->get();
header('Location:../client/dashboard.php');
exit();
?>
the gog.php which includes the settings (i deleted the values)
<?php
require_once "vendor/autoload.php";
$gClient = new Google_Client();
$gClient->setClientId("");
$gClient->setClientSecret("");
$gClient->setApplicationName("");
$gClient->setRedirectUri("");
$gClient->addScope("");
$loginURL = $gClient->createAuthUrl();
?>
the index php where it testes wether or not the user is signed in with google account or email pwd
<?php
require_once("includes/config.php");
require_once("gog.php");
require_once("includes/classes/Account.php");
$account=new Account($con);
if(isset($_SESSION["clientLoggedIn"]) || isset($_SESSION['access_token']) ){
header('location:client/dashboard.php');
exit();
}
?>
the config.php file included which has the database setting to connect
<?php
ob_start();
session_start();
try{
$con= new PDO("mysql:dbname=cinecad;host=localhost","root","");
$con->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING);
}catch(PDOException $e){
exit("Connexion failed:".$e->getMessage());
}
?>
and the finally the dashbaord.php
<?php
session_start();
if(!isset($_SESSION["clientLoggedIn"])||!isset($_SESSION['access_token'])){
header("Location:../index.php");
}
?>
Upvotes: 0
Views: 602
Reputation: 41
Based on @Alon Eitan comment the answer was $_SESSION["clientLoggedIn"] = true
Upvotes: 1