为了账号安全,请及时绑定邮箱和手机立即绑定

从特定页面重定向时更改文本...?

从特定页面重定向时更改文本...?

PHP
白衣染霜花 2022-12-11 09:44:22
正如标题所暗示的那样,我正在尝试使用相同的 .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贡献1757条经验 获得超7个赞

在你调用之前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']);

}

另外仅供参考,您应该使用准备好的语句。您的代码并不完全安全


查看完整回答
反对 回复 2022-12-11
  • 1 回答
  • 0 关注
  • 83 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号