没有文件的时候没有这样的文件?

时间:2019-03-29 02:49:32

标签: php mysql xampp

我正在尝试使用PHP设置Google登录身份验证系统,以将其数据发送到MySQL数据库。我已经完成了所有工作并将它们全部放入我的C:\ xampp \ htdocs目录,但这是在我打开http://localhost/login.php

时发生的情况

警告:require_once(googleapi / vendor / autoload.php):无法打开流:第3行的C:\ xampp \ htdocs \ config.php中没有此类文件或目录

严重错误:require_once():无法在第3行的C:\ xampp \ htdocs \ config.php中打开所需的'googleapi / vendor / autoload.php'(include_path ='C:\ xampp \ php \ PEAR')

这是我所有的密码

//login.php file
<?php
    require_once "config.php";
    if (isset($_SESSION['access_token'])) {
        header('Location: index.php');
        exit();
    }
    $loginURL = $gClient->createAuthUrl();
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0,">
          <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Login</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
</head>
<body>
<div class="container" style="margin-top: 100px">
    <div class="row justify-content-center">
        <div class="col-md-6 col-offset-2" align="center">
        <form>
        <input type="text" placeholder="Email" name="email" class="form-control"><br>
        <input type="password" placeholder="Password" name="password" class="form-control"><br>
        <input type="button" onclick="window.location = '<?php echo $loginURL ?>';"  name="google" value="Login with Google" class="btn btn-primary">
        <input type="reset" name="submit" value="Clear" class="btn btn-primary">
        </form> 
        </div>  
    </div>
</div>
</body>
</html>

//config.php file
<?php
    session_start();
    require_once "googleapi/vendor/autoload.php";
    $gClient = new Google_Client();
    $gClient->setClientId("<removed>");
    $gClient->setClientSecret("<removed>");
    $gClient->setApplicationName("capstoneproject");
    $gClient->setRedirectUri("http://localhost/login/g-callback.php");
    $gClient->addScope("https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email");    
    $con = new mysqli('localhost', 'root','' ,'table');
    if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
}   
?>

//index.php file
<?php
    session_start();
    if (!isset($_SESSION['access_token'])) {
        header('Location: login.php');
        exit();
    }
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Login With Google</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
</head>
<body>
<div class="container" style="margin-top: 100px">
    <div class="row">
        <div class="col-md-3">
            <img style="width: 80%;" src="<?php echo $_SESSION['picture'] ?>">
        </div>
        <div class="col-md-9">
            <table class="table table-hover table-bordered">
                <tbody>
                    <tr>
                        <td>ID</td>
                        <td><?php echo $_SESSION['id'] ?></td>
                    </tr>
                    <tr>
                        <td>First Name</td>
                        <td><?php echo $_SESSION['givenName'] ?></td>
                    </tr>
                    <tr>
                        <td>Last Name</td>
                        <td><?php echo $_SESSION['familyName'] ?></td>
                    </tr>
                    <tr>
                        <td>Email</td>
                        <td><?php echo $_SESSION['email'] ?></td>
                    </tr>
                    <tr>
                        <td>Gender</td>
                        <td><?php echo $_SESSION['gender'] ?></td>
                    </tr>
                    <tr>
                        <td>Logout</td>
                        <td><a href="logout.php">Logout</a></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
</html>
//g-callback.php
<?php
    require_once "config.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: login.php');
        exit();
    }
    $oAuth = new Google_Service_Oauth2($gClient);
    $userData = $oAuth->userinfo_v2_me->get();
    $_SESSION['id'] = $userData['id'];
    $_SESSION['email'] = $userData['email'];
    $_SESSION['gender'] = $userData['gender'];
    $_SESSION['picture'] = $userData['picture'];
    $_SESSION['familyName'] = $userData['familyName'];
    $_SESSION['givenName'] = $userData['givenName'];
 $sql="insert into google_users (clint_id,name,last_name,google_email,gender,picture_link) values
 ('".$userData['id']."','".$userData['givenName']."','".$userData['familyName']."','".$userData['email']."',
 '".$userData['gender']."','".$userData['picture']."')";
    mysqli_query($con,$sql);
    header('Location: index.php');
    exit();
?>

0 个答案:

没有答案