我的問題是我想創建一個登錄屏幕,註冊表單和丟失的密碼錶單。我設法在登錄屏幕上創建了一條錯誤消息,但是在註冊表單中執行時卻沒有這樣做。 所以我的問題是,我怎樣才能將我的註冊表單參數添加到函數auth中,它將爲註冊表單執行相同操作?php登錄的一些問題
case "authent":
auth();
break;
function auth(){
global $myurl;
$errors=array();
$username="";
$passwd="";
if (isset($_POST['username']) && $_POST['username']!="") {
$username=$_POST['username'];
} else {
$errors[]="Username missing!";
}
if (isset($_POST['passwd']) && $_POST['passwd']!="") {
$passwd=$_POST['passwd'];
} else {
$errors[]="Password missing, fill the blank!";
}
if (empty($errors)){
// no errors, check the information
if ($username=="user" && $passwd=="password"){
// correct information
header("Location: $myurl?mode=success");
} else {
// wrong information, back to login.html
$errors[]="Vale info, proovi uuesti.";
include("view/login.html");
}
} else {
// errors with messages
include("view/login.html");
}
}
你爲什麼要包括的login.php頁面?如果有任何錯誤,那麼你在同一頁面上。只顯示錯誤(s)。 – user3470953
感謝您指出,我的計劃是爲錯誤彈出一個錯誤,這只是一個暫時的事情。你有什麼想法如何讓函數適用於多種情況? – user3225423