Create a Basic Login System with PHP
<?php
error_reporting(E_ALL);
ini_set(‘display_errors’, 1);
// password prtected code
if (isset($_POST[‘password’])) {
if ($_POST[‘password’] == ‘password’) {
setcookie(“password”, $_POST[‘password’], time()+(10*365*24*60*60));
header(‘Location: ‘.$_SERVER[‘REQUEST_URI’]);
}
}
if(isset($_COOKIE[‘password’])) {
if($_COOKIE[‘password’] == ‘password’) {
}
}else{
?>
<div class=”data-form”>
<h2>Password Protected Site</h2>
<form class=”password-form” method=”post” action=””>
<input type=”text” name=”password” value=”password”>
<input type=”submit” name=”login”>
</form>
<div data-lastpass-icon-root=”” style=”position: relative !important; height: 0px !important; width: 0px !important; float: left !important;”>
</div>
</div>
<style type=”text/css”>
.data-form {
display: flex;
height: 97vh;
justify-content: center;
align-items: center;
flex-direction: column;
}
form.password-form input {
height: 35px!important;
margin-right: 0;
border: 1px solid silver;
width: 200px;
}
form.password-form input[type=”submit”] {
background: #000;
border: 0;
padding: 0 20px;
color: #fff;
width: auto;
}
h2 {
font-family: cursive;
}
</style>
<?php
exit;
}