这是我的 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 关注
- 117 浏览
添加回答
举报
0/150
提交
取消