PHP没有';t重定向到特定页面
我试图向PHP命令发送密码。但当我PHP没有';t重定向到特定页面,php,html,css,twitter-bootstrap-3,Php,Html,Css,Twitter Bootstrap 3,我试图向PHP命令发送密码。但当我echoit检查条件时,它工作了。但是如果我不使用echo,而是使用headers(),那么如果密码正确,它将不会重定向。但如果密码不正确,它将重定向到错误页面以显示错误 这是我的密码 <?php //require_once "condb.php"; ?> <?php if (isset($_POST['BTN_ENTER'])) { $password=$_POST['password']; //echo $p
echo
it检查条件时,它工作了。但是如果我不使用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>
登录
div#索引
{
高度:100px;
位置:绝对位置;
排名:0;
底部:0;
左:0;
右:0;
保证金:自动;
}
请输入密码
ตกลง
你能试试这个吗
if ($password == "test")
{
header('Location: survey.php', true, 302);
die();
}
else
{
header('Location: error.php', true, 302);
die();
}
如果要全局访问值,首先应该使用会话或cookie 尝试使用javascript代码段进行重定向
echo "<script>window.location='survey.php';"</script>";
echo“window.location='survey.php';”;
它没有显示任何错误。感谢您的回答。我刚刚忘记了“$\u会话”。