Создать простой сайт, где будет страница с формой для авторизации и страница для авторизованного пользователя.
<?php
require("header.php");
$errors = array();
$form_valid = true;
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["btnLogin"]))
{
$login = $_POST['txtLogin'];
$password = $_POST['txtPassword'];
if (empty($login))
{
$form_valid = false;
$errors["login"] = "Please enter login.";
}
if (empty($password))
{
$form_valid = false;
$errors["password"] = "Please enter password.";
}
if ($form_valid)
{
$login_result = $authentication->doLogin($login, $password);
if (!$login_result)
{
$errors["wrong_login"] = "Invalid login or password.";
}
else
{
header("Location: content.php");
die();
}
}
else
{
$authentication->logoff();
}
}
?>
<?php
if (count($errors) > 0)
{
?>
<ul style="color: #f00">
<?php
foreach ($errors as $key => $value)
{
echo "<li>".$value."</li>";
}
?>
</ul>
<?php
}
?>
<div class="row">
<div class="col-md-6">
<div class="row justify-content-center align-items-center h-100">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" class="needs-validation" novalidate>
<div class="form-group">
<label for="txtLogin">Login</label>
<input type="text" class="form-control" id="txtLogin" name="txtLogin" required />
<div class="invalid-feedback">
Please enter login.
</div>
</div>
<div class="form-group">
<label for="txtPassword">Password</label>
<input type="password" class="form-control" id="txtPassword" name="txtPassword" required />
<div class="invalid-feedback">
Please enter password.
</div>
</div>
<button type="submit" name="btnLogin" class="btn btn-primary">Login</button>
</form>
</div>
</div>
<div class="col-md-4">
<p>
<strong>Login:</strong> user1<br/>
<strong>Password:</strong> a
</p>
<p>
<strong>Login:</strong> user2<br/>
<strong>Password:</strong> a
</p>
</div>
</div>
<?php
require("footer.php");
?>
<script type="text/javascript">
(function() {
'use strict';
window.addEventListener('load', function() {
var forms = document.getElementsByClassName('needs-validation');
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
</script>