Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- index.php
- <?php
- $error = "";
- if(isset($_POST['username'],$_POST['password'])){
- /*** username & passwords ***/
- $user = array(
- "user" => "admin",
- "pass"=>"admin"
- );
- $username = $_POST['username'];
- $pass = $_POST['password'];
- if($username == $user['user'] && $pass == $user['pass']){
- session_start();
- $_SESSION['simple_login'] = $username;
- header("Location: home.php");
- exit();
- }else{
- $error = '<div class="alert alert-danger">Invalid Login</div>';
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>Simple php login without database by php-gym.com</title>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
- <style type="text/css">
- body{padding-top:20px;}
- </style>
- </head>
- <body>
- <h3 class="panel-title">Please sign in</h3>
- <?php echo $error; ?>
- <form accept-charset="UTF-8" role="form" method="post" action="index.php">
- <fieldset>
- <input placeholder="Username" name="username" type="text">
- <input placeholder="Password" name="password" type="password" value="">
- <input type="submit" value="Login">
- </fieldset>
- </form>
- </body>
- </html>
- logout.php
- <?php
- session_start();
- unset($_SESSION['simple_login']);
- header("Location: index.php");
- ?>
- home.php
- <?php
- session_start();
- if(!isset($_SESSION['simple_login'])){
- header("Location: index.php");
- exit();
- }
- /*** you can write your protected content here ***/
- ?>
- <h1 align="center">Welcome, <?php echo $_SESSION['simple_login']; ?></h1>
- <p align="center"><a href="logout.php">Logout</a></p>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement