Advertisement
Guest User

Untitled

a guest
May 14th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. index.php
  2.  
  3. <?php
  4. $error = "";
  5. if(isset($_POST['username'],$_POST['password'])){
  6.  
  7. /*** username & passwords ***/
  8. $user = array(
  9. "user" => "admin",
  10. "pass"=>"admin"
  11. );
  12. $username = $_POST['username'];
  13. $pass = $_POST['password'];
  14. if($username == $user['user'] && $pass == $user['pass']){
  15. session_start();
  16. $_SESSION['simple_login'] = $username;
  17. header("Location: home.php");
  18. exit();
  19. }else{
  20. $error = '<div class="alert alert-danger">Invalid Login</div>';
  21. }
  22. }
  23. ?>
  24. <!DOCTYPE html>
  25. <html lang="en">
  26. <head>
  27. <meta charset="utf-8">
  28. <title>Simple php login without database by php-gym.com</title>
  29. <meta name="viewport" content="width=device-width, initial-scale=1">
  30.  
  31.  
  32. <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
  33. <style type="text/css">
  34. body{padding-top:20px;}
  35. </style>
  36. </head>
  37. <body>
  38.  
  39. <h3 class="panel-title">Please sign in</h3>
  40.  
  41. <?php echo $error; ?>
  42. <form accept-charset="UTF-8" role="form" method="post" action="index.php">
  43. <fieldset>
  44.  
  45. <input placeholder="Username" name="username" type="text">
  46.  
  47. <input placeholder="Password" name="password" type="password" value="">
  48.  
  49. <input type="submit" value="Login">
  50. </fieldset>
  51. </form>
  52.  
  53. </body>
  54. </html>
  55.  
  56. logout.php
  57.  
  58. <?php
  59. session_start();
  60. unset($_SESSION['simple_login']);
  61. header("Location: index.php");
  62. ?>
  63.  
  64. home.php
  65.  
  66. <?php
  67. session_start();
  68. if(!isset($_SESSION['simple_login'])){
  69. header("Location: index.php");
  70. exit();
  71. }
  72.  
  73. /*** you can write your protected content here ***/
  74.  
  75. ?>
  76. <h1 align="center">Welcome, <?php echo $_SESSION['simple_login']; ?></h1>
  77. <p align="center"><a href="logout.php">Logout</a></p>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement