当用户点击登录按钮时,我正在尝试更改页面。当前点击登录按钮时,页面刚刚刷新,用户不会被重定向到新页面。我在页面的任何代码之前创建了会话。我想知道它是否与我的 header 命令的位置有关。
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login</title>
</head>
<body>
<form action="" method="post">
<br>Name: <input type="text" name="NameTextBox"><br>
<br>What grade are you currently in?: <input type="number" name="GradeTextBox"><br>
<br><button name="Login" type="submit">Login</button></br>
</form>
<?php
if (isset($_POST["Login"])) {
$_SESSION["start"] = $_SERVER['REQUEST_TIME'];
//echo "This session is beginning at ".$_SESSION["start"]."<br /><br />";
}
if(isset($_POST["Login"])){
if($NameTextBox = "Phydeaux"){
//echo"Good Name!";
PassLogin();
}
elseif($NameTextBox = "Rover"){
//echo"Good Name!";
PassLogin();
}
elseif($NameTextBox = "Spot"){
//echo"Good Name!";
PassLogin();
}
else{
echo"You cannot login!";
}
}
function PassLogin()
{
//print '<script type="text/javascript">';
//print 'alert("Running PassLogin Function")';
//print '</script>';
$_SESSION["ReadingGrade"] = "Fail";
$_SESSION["WritingGrade"] = "Fail";
$_SESSION["MathGrade"] = "Fail";
$_SESSION["Grade"] = $GradeTextBox;
$_SESSION["Name"] = $NameTextBox;
Header('Location: Reading.php');
}
if (isset($_POST["Login"])){
//echo "Login has been pressed";
}
?>
</body>
</html>