正如标题所示,我正在尝试使用相同的 .php 页面,并让它在从特定位置重定向时显示新的内容。在上下文中...我有一个登录,成功登录后重定向到主页,但如果不成功,则重定向到索引。有没有办法让我的索引页面在从登录页面重定向时显示“登录错误”消息?这是我的登录代码...<?phpsession_start();include('conn.php');$query = "SELECT * FROM User";$result = mysqli_query($conn, $query) or die(mysqli_error($conn));if (isset($_POST["submit"])) { $logEmail = $conn->real_escape_string($_POST['logEmail']); $logPass = $conn->real_escape_string($_POST['logPass']); $checkuser = "SELECT * FROM User WHERE Email='$logEmail' AND UserPassword=AES_ENCRYPT('$logPass', 'MyKey')"; $userresult = mysqli_query($conn, $checkuser) or die(mysqli_error($conn)); $loginsucc = (mysqli_num_rows($userresult) > 0); if (mysqli_num_rows($userresult) > 0) { while ($row = mysqli_fetch_assoc($userresult)) { $userPriKey = $row['UserID']; $userid = $row['Email']; $accounttype = $row['IsAdmin']; $firstname = $row['FirstName']; $surname = $row['LastName']; $_SESSION['userPriKey'] = $userPriKey; $_SESSION['name'] = $firstname; $_SESSION['surname'] = $surname; $_SESSION['Email'] = $userid; $_SESSION['IsAdmin'] = $accounttype; if($accounttype == '1'){ header("Location: home.php"); }else if ($accounttype == '0'||$accounttype == NULL ) { header("Location: userhome.php"); } } } else { header("Location: index.php"); }}?>
1 回答
慕慕森
TA贡献1856条经验 获得超17个赞
在调用之前header()设置一个会话变量,如下所示
$_SESSION['msg'] = 'success you are logged in';
header('Location: page.php');
exit;
然后在page.php中,
session_start();
if (isset($_SESSION['msg'])) {
echo $_SESSION['msg'];
unset($_SESSION['msg']);
}
另外仅供参考,您应该使用准备好的语句。您的代码并不完全安全
- 1 回答
- 0 关注
- 78 浏览
添加回答
举报
0/150
提交
取消