PHP

SIMPLE LOGIN SYSTEM IN PHP WITHOUT DATABASE

HTML LOGIN FORM <form method="post" target="_self">   <input type="text" name="user"/>   <input type="password" name="pass"/>    <input type="submit" value="login"/> </form>

HTML LOGIN FORM

01

PROCESS LOGIN ON FORM SUBMIT <?php require "LOGIN.PHP"; ?>

START SESSION session_start();

PHP LOGIN PROCESS (A)

02

LIST OF USERS & PASSWORDS $users = [   "jon"=>"SECRET123",   "job"=>"SECRET234", ];

PHP LOGIN PROCESS (B)

03

REDIRECT TO HOME PAGE ON LOGIN if (isset($_SESSION['user'])) {    header("Location: index.php");   exit(); }

CHECK & VERIFY if (isset($_POST["user"])) { if ($users [$_POST["user"]] == $_POST["pass"]) {   $_SESSION["user"] = $_POST["user"];  }}

ON TOP OF ALL PAGES -  CHECK IF USER SIGNED IN if (!isset($_SESSION["user"])) {    header("Location: login.php");   exit();  }

PROTECT OTHER PAGES

04

LOGOUT FORM <form method="post">   <input type="hidden"                name="logout" value="1"/>    <input type="submit"                 value="Logout"/> </form>

LOGGING OFF

05

PHP END SESSION if (isset($_POST["logout"])) { unset($_SESSION["user"]); }