亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從特定頁面重定向時更改文本...?

從特定頁面重定向時更改文本...?

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 關注
  • 96 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號