0
간단한 로그인을 만들고 폴더의 일부 페이지를 보호하려고합니다. 사용자가 username/pwd를 입력하면 페이지가 다른 폴더의 index.php
으로 리디렉션됩니다.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; ?>
난 그냥 빈 화면을 얻을. 나는 값의 왜곡이 아닌지 왜 모르겠다.