繁体   English   中英

如何修复页面未正确重定向

[英]How to fix The page isn’t redirecting properly

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();


?>

gog.php 包括设置(我删除了值)

<?php
    require_once "vendor/autoload.php";
    $gClient = new Google_Client();
    $gClient->setClientId("");
    $gClient->setClientSecret("");
    $gClient->setApplicationName("");
    $gClient->setRedirectUri("");
    $gClient->addScope("");
    $loginURL = $gClient->createAuthUrl();


?>

索引 php 测试用户是否使用谷歌帐户或 email 密码登录

<?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();
}
?>

包含的 config.php 文件,其中包含要连接的数据库设置

<?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());
}

?>

最后是dashbaord.php

<?php
session_start();

if(!isset($_SESSION["clientLoggedIn"])||!isset($_SESSION['access_token'])){

    header("Location:../index.php");
}



?>

根据@Alon Eitan 的评论,答案是 $_SESSION["clientLoggedIn"] = true

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM