0
當用戶輸入不正確的用戶名或密碼時,我正在尋找在頁面上顯示錯誤消息。現在它使用彈出框來顯示消息,但我希望它在頁面上。我會如何去做這件事?下面是我的php如何在沒有彈出框的情況下在php登錄時顯示錯誤消息
<?php
if(!defined("SESSION")){
session_start();
define("SESSION", true);
}
if(isset($_GET["log_out"])){
unset($_SESSION["logged_in"]);
header('refresh: 0; url=login.php');
exit;
}
$login = true;
require "protect.php";
$logins[0]["user"] = "";
$logins[0]["pass"] = "";
$logins[0]["redirect"] = "test.php";
$logins[1]["user"] = "";
$logins[1]["pass"] = "";
$logins[1]["redirect"] = "";
$logins[2]["user"] = "";
$logins[2]["pass"] = "";
$logins[2]["redirect"] = "test.php";
// No need to edit below, except the errors
if(isset($_POST['submit'])){ //is the form submitted?
if(empty($_POST['user']) || empty($_POST['pass'])){
header("Location: login.php");
exit;
} //check for empty user name or password
$is_logged = false; //this is part of the process to see if they have a correct password or not, set to false right here to say no right pass... (will change later)
foreach($logins as $login){
$user = $_POST;
if(($user["user"] == $login["user"]) && ($user["pass"] == $login["pass"])) {
$is_logged = true;
$_SESSION["logged_in"] = array($login["redirect"], true); //now, if they do have a correct password, set the session to true, and the variable.
header("Location: ".$login["redirect"]);
exit;
}
}
if(!$is_logged){ echo '<script type="text/javascript">alert("Inncorect username or password");window.history.go(-1);</script>'; } //if none of the $logins arrays matched the input, give an error
}
?>
這個偉大的工程,但我會怎樣的形式下,顯示它吧?這顯示在頁面頂部 – Tyler 2013-04-29 02:40:56
我建議你瀏覽一些在互聯網上的教程,或者購買一本關於如何使用HTML和PHP的書。實驗!試着找出如何把它放在頁面頂部,而不是試圖讓其他人爲你做所有的工作! 當然,當你需要時尋求幫助 - 但是如何做這樣的事情還有很多信息。你只需要看:)。 – shadrx 2013-04-29 06:22:46