我有一个简单的表格,$_Session
当密码错误时它不会打印我的错误消息。除了错误消息之外它工作正常,实际上错误消息在我输入之前一直有效header("Location: /cms/");
。我做错了什么吗?
<?php
session_start();
$error_msg = "";
if($_POST['username']) {
$username = $_POST['username'];
$password = $_POST['password'];
$admin = "a";
$adminpass = "s";
if(($username != $admin) || ($password != $adminpass)) {
$error_msg = 'Your login information is wrong dude!';
}
else {
$_SESSION['admin'] = '$username';
header("Location: /cms/");
exit();
}
}
if(!isset($_SESSION['admin'])) {
header("Location: /cms/login");
exit();
}
?>
<html>
<body>
<form action="/cms/loggedin.php" method="post" target=_self>
<label>Username: <input type="text" name="username" id="username"></label>
<font color="#FF0000"><?php echo $error_msg; ?></font><br />
<br />
<label>Password: <input type="text" name="password" id="password"></label>
<br />
<br />
<label><input type="submit" name="Submit" value="Sign In"></label>
</form>