-1
我试图发送密码到PHP命令。但是当我echo
它检查条件,它的工作原理。但是如果我不是echo
,而是使用headers()
代替,如果密码正确,它将不会重定向。但是如果密码不正确,它会重定向到错误页面以显示错误。PHP不重定向到特定页面
这是我的代码。
<?php
//require_once "condb.php";
?>
<?php
if (isset($_POST['BTN_ENTER']))
{
$password=$_POST['password'];
//echo $password;
if ($password == "test")
{
//echo "ok!";
header('location:survey.php');
}else
{
//echo "not ok!";
header('location:error.php');
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Login</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
</script>
<script src="js/bootstrap.min.js"></script>
</head>
<style>
div#index
{
height: 100px;
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
</style>
<body style="background-color:#4da6ff;">
<div align="center" id="index" class="row col-sm-12 col-md-6 col-lg-12 col-xs-12">
<p style="font-size:32px;color:#66ff33;">Please enter passcode.</p>
<form method="POST">
<div align="center" class="row col-sm-12 col-md-12 col-lg-12 col-xs-12"
style="margin:0 auto;">
<input type="password" class="form-control input-lg" placeholder="Please enter a passcode." style="width:40%;height:50%" name="password" autofocus><br>
</div>
<button type="submit" class="btn btn-success btn-lg" name="BTN_ENTER"
style="height:50%;width:20%;">ตกลง
</button>
</form>
</div>
它并没有表现出任何错误。谢谢您的回答。我只是忘记了“$ _SESSION”。 – PaoPaoMC