這是我的 PHP Google 登錄腳本。它在本地主機上工作,但是當我把它放在在線服務器上時它不工作。我想重定向特定頁面但不重定向。身份驗證后顯示 HTTP ERROR 500。解決方案是什么?在本地主機上它的工作順利。但在在線服務器中顯示 HTTP ERROR 500。為什么?authenticate.php<?php require_once 'config.php';if(isset($_GET['code'])){ $googleClient->authenticate($_GET['code']); $_SESSION['token'] = $googleClient->getAccessToken(); header('Location: ' . filter_var($redirectURL, FILTER_SANITIZE_URL));}############ Set Google access token ############if (isset($_SESSION['token'])) { $googleClient->setAccessToken($_SESSION['token']);}if ($googleClient->getAccessToken()) { ############ Fetch data from graph api ############ try { $gpUserProfile = $google_oauthV2->userinfo->get(); } catch (\Exception $e) { echo 'Graph returned an error: ' . $e->getMessage(); session_destroy(); header("Location: ./"); exit; } ############ Store data in database ############ $oauthpro = "google"; $oauthid = $gpUserProfile['id'] ?? ''; $first_name = $gpUserProfile['given_name'] ?? ''; $last_name = $gpUserProfile['family_name']; $email_id = $gpUserProfile['email'] ?? ''; $picture = $gpUserProfile['picture'] ?? ''; $sql = "SELECT * FROM users WHERE oauthid='".$gpUserProfile['id']."'"; $result = $conn->query($sql); if ($result->num_rows == 1) { $conn->query("UPDATE users SET first_name='".$first_name."', last_name='".$last_name."', email_id='".$email_id."', picture='".$picture."' where oauthid='".$oauthid."' "); } else { $conn->query("INSERT INTO users (oauth_pro, oauthid, first_name, last_name, email_id, picture) VALUES ('".$oauthpro."', '".$oauthid."', '".$first_name."', '".$last_name."', '".$email_id."', '".$picture."')"); } $res = $conn->query($sql); $Loggedin = $res->fetch_assoc(); $_SESSION['Loggedin'] = $Loggedin; header("Location: ../../study.php");} else { header("Location:/");}
1 回答

瀟瀟雨雨
TA貢獻1833條經驗 獲得超4個贊
是的!我得到了答案。
當我使用 (.cf) 域或任何其他免費域或免費托管時,它無法在在線服務器上運行。但是,當我嘗試使用付費頂級域并托管時,它可以正常工作。
- 1 回答
- 0 關注
- 133 瀏覽
添加回答
舉報
0/150
提交
取消