我的登錄頁面正常工作。強制登錄頁面首先顯示
它不使用用戶數據庫,它在代碼中使用預定義的用戶名和密碼。我無法做的唯一事情就是在index.php之前首先顯示登錄頁面。任何人都可以鍵入index.php
,並且該網站將打開,因此它不使用登錄頁面。
這裏是我的login.php
<?php
ob_start();
session_start();
?>
<html lang = "en">
<head>
<title>Alpine VW Extension List</title>
<link href = "css/bootstrap.min.css" rel = "stylesheet">
<style>
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #ADABAB;
}
.form-signin {
max-width: 330px;
padding: 15px;
margin: 0 auto;
color: #017572;
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
margin-bottom: 10px;
}
.form-signin .checkbox {
font-weight: normal;
}
.form-signin .form-control {
position: relative;
height: auto;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 10px;
font-size: 16px;
}
.form-signin .form-control:focus {
z-index: 2;
}
.form-signin input[type="email"] {
margin-bottom: -1px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
border-color:#017572;
}
.form-signin input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
border-color:#017572;
}
h2{
text-align: center;
color: #017572;
}
</style>
</head>
<body>
<h2>Welcome, Please Login</h2>
<div class = "container form-signin">
<?php
$msg = '';
if (isset($_POST["login"]) && !empty($_POST["username"])
&& !empty($_POST['password'])) {
if ($_POST["username"] == "admin" &&
$_POST["password"] == "admin") {
$_SESSION["valid"] = true;
$_SESSION["timeout"] = time();
$_SESSION["username"] = "admin";
header("location:index.php");
}else {
$msg = 'Wrong username or password';
}
}
?>
</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 = tutorialspoint"
required autofocus></br>
<input type = "password" class = "form-control"
name = "password" placeholder = "password = 1234" required>
<button class = "btn btn-lg btn-primary btn-block" type = "submit"
name = "login">Login</button>
</form>
</div>
</body>
</html>
檢查登錄索引頁 - 如果他們沒有登錄重定向到登錄頁面。 –