
我使用 php 控制表單元素。如果它們無效,我會在它們下面列印一條錯誤訊息。我的問題是當表單中的每個元素都為真時,頁面沒有重定向到我想要的目標頁面,它顯示一個空的 logintest.php (在 php 檔案夾內)而不是重定向它。這是我的 index.php 代碼(實際上是登錄頁面)
<form action="../php/logintest.php" method="post">
<div class="form-group">
<input type="email" name="email" class="form-control" id="name" placeholder="Username-mail">
<?php if(isset($nameError)) { ?>
<?php echo "<span style='color:red;'>$nameError</span>"; ?>
<?php } ?>
</div>
<div class="form-group">
<input type="password" name="password" class="form-control" id="parola" placeholder="Password">
<?php if(isset($parolaError)) {?>
<?php echo "<span style='color:red;'>$parolaError</span>"; ?>
<?php } ?>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="accept" name="checker">
<p class=ctrlButton>You have to accept the terms.</p>
<?php if(isset($checkBoxError)) {?>
<?php echo "<span style='color:red;'>$checkBoxError</span>"; ?>
<?php } ?>
</div>
<div class="form-group">
<input type="submit" name="submit" value="Enter" id="submit" class="btn btn-outline-danger login_btn">
</div>
</form>
而我的 logintest.php 代碼是..
<?php
$nameError="";
$parolaError="";
$checkBoxError="";
if(isset($_POST['checker'])){
if(isset($_POST['email']) && isset($_POST['password']) ){
if($_POST['password']=="123" && $_POST['email']=="[email protected]"){
//true input
// window.open('https://github.com/', '_blank');
header("location:https://www.google.com");
}
if($_POST['password']!="b211210381"){
$parolaError='Parola is wrong';
// header('Location: index.php');
}
if($_POST['email']!="[email protected]" ){
$nameError='Wrong email try again';
// header('Location: index.php');
}
}
else{
if($_POST['password']==""){
$parolaError='Enter a parola';
}
if($_POST['email']==""){
$nameError='Enter a userName';
}
}
}
else {
$checkBoxError='Please accept the terms';
}
include('../index.php');
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL ^ E_NOTICE);
?>
uj5u.com熱心網友回復:
我相信一旦設定了標頭位置,您就無法設定標頭位置,請在此處查看接受的答案:如何修復 PHP 中的“標頭已發送”錯誤
我不確定我會因為提供這個解決方案而受到多少仇恨,但這對我來說很有用:( 0 是以秒為單位的時間,所以你可以添加延遲)
echo '<meta http-equiv="refresh" content="0; URL=https://www.google.com">';
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/475276.html
上一篇:未捕獲的語法錯誤:<script></script>的輸入意外結束
下一篇:如何使用字串中的HTML代碼?
