我正在尝试创建一个简单的登录并保护文件夹中的某些页面。用户输入用户名/密码后,该页面会将其重定向到另一个文件夹中的index.php
。
在index.php
中,我正在尝试验证登录信息。这里的代码是测试SESSION参数中是否有任何值。
当我重定向到index.php
时,没有任何内容显示。
的login.php
<?php
ob_start();
session_start();
if(isset($_GET[redirect_url])) {
$_SESSION[redirect] = $_GET[redirect_url];
}
?>
<h2>Enter Username and Password</h2>
<div class = "container form-signin">
<?php
$msg = '';
if (isset($_POST["login"]) && !empty($_POST["username"]) && !empty($_POST["password"])) {
if ($_POST["username"] == '1234' && $_POST["password"] == '1234') {
$_SESSION["login"] = true;
$_SESSION["timeout"] = time();
if(isset($_SESSION["redirect"])) {
$url = $_SESSION["redirect"] . "/index.php";
header("Location:" . $url);
unset($_SESSION["redirect"]);
}
}
else {
$msg = "Login Failed!";
}
}
?>
</div> <!-- /container -->
<div class = "container">
<form class = "form-signin" role = "form"
action = "<?php echo htmlspecialchars($_SERVER['PHP_SELF']);
?>" method = "post">
<h4 class = "form-signin-heading"><?php echo $msg; ?></h4>
<input type = "text" class = "form-control"
name = "username" placeholder = "username"
required autofocus></br>
<input type = "password" class = "form-control"
name = "password" placeholder = "password" required>
<button class = "btn btn-lg btn-primary btn-block" type = "submit"
name = "login">Login</button>
</form>
Click here to clean <a href = "logout.php" tite = "Logout">Session.
</div>
重定向页面:
<?php
echo $_SESSION["login"];
echo $_SESSION["timeout"];
exit; ?>
我只是得到一个空白的屏幕。我不确定为什么没有这些值存在。
答案 0 :(得分:1)
第二页需要RESTRICT
。
function max(array) {
if (array.length === 0) { // Step1: set up your base case
return array[0]
} else {
return Math.max(array.shift(), max(array); // Step2: rec case
}
}