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

正如标题所示,我正在尝试使用相同的 .php 页面,并让它在从特定位置重定向时显示新的内容。

在上下文中...我有一个登录,成功登录后重定向到主页,但如果不成功,则重定向到索引。有没有办法让我的索引页面在从登录页面重定向时显示“登录错误”消息?

这是我的登录代码...

<?php

session_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");

    }

}


?>


月关宝盒
浏览 79回答 1
1回答

慕慕森

在调用之前header()设置一个会话变量,如下所示$_SESSION['msg'] = 'success you are logged in';header('Location: page.php');exit;&nbsp;然后在page.php中,session_start();if (isset($_SESSION['msg'])) {&nbsp; &nbsp; echo $_SESSION['msg'];&nbsp; &nbsp; unset($_SESSION['msg']);}另外仅供参考,您应该使用准备好的语句。您的代码并不完全安全
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5