我试图在输入用户名和密码后重定向到其他名为panel.php的页面,但在将Currect值放入表单目标页面后,再次将我重定向到登录表单.我的登录码->;
<?php
session_start();
$login='
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>login</title>
</head>
<body>
<h1> login form</h1>
<pre>
<form method="POST" action="panel.php" >
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" name="submit">
</form>
</body>
</html>
';
if(isset($_POST['username']) && isset($_POST['password'])){
$username= $_POST['username'];
$password= $_POST['password'];
if ($username == 'teddy' && $password == '123'){
$_SESSION['X'] = true;
$_SESSION['username'] = $username;
header('location: panel.php');
exit();
}
else{
echo "invalid credentials";
}
}
else
{
echo $login;
}
?>
和面板代码->;
<?php
session_start();
$panel = '
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>panel</title>
</head>
<body>
<p>welcom to the panel; dear ' . $_SESSION['username'] . ' </p>
</body>
</html>
';
if ($_SESSION['X'] === true){
echo $panel;
}
else{
header('location: login.php');
}
?>
我try 使用会话查看面板页面