我尝试向PHP命令发送密码。但是当我echo
检查条件时,它可以工作。但是,如果我不是echo
而是使用headers()
,那么如果密码正确,则不会重定向。但如果密码不正确,则会重定向到错误页面以显示错误。
这是我的代码。
<?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>
答案 0 :(得分:0)
你能试试吗?
if ($password == "test")
{
header('Location: survey.php', true, 302);
die();
}
else
{
header('Location: error.php', true, 302);
die();
}
答案 1 :(得分:0)
如果要全局访问该值,首先应使用会话或cookie。
尝试使用javascript代码段进行重定向
echo "<script>window.location='survey.php';"</script>";