PHP - Login example


SUBMITTED BY: efbee

DATE: Oct. 3, 2016, 3:53 p.m.

FORMAT: PHP

SIZE: 3.5 kB

HITS: 710

  1. <?php
  2. ob_start();
  3. session_start();
  4. ?>
  5. <?
  6. // error_reporting(E_ALL);
  7. // ini_set("display_errors", 1);
  8. ?>
  9. <html lang = "en">
  10. <head>
  11. <title>Tutorialspoint.com</title>
  12. <link href = "css/bootstrap.min.css" rel = "stylesheet">
  13. <style>
  14. body {
  15. padding-top: 40px;
  16. padding-bottom: 40px;
  17. background-color: #ADABAB;
  18. }
  19. .form-signin {
  20. max-width: 330px;
  21. padding: 15px;
  22. margin: 0 auto;
  23. color: #017572;
  24. }
  25. .form-signin .form-signin-heading,
  26. .form-signin .checkbox {
  27. margin-bottom: 10px;
  28. }
  29. .form-signin .checkbox {
  30. font-weight: normal;
  31. }
  32. .form-signin .form-control {
  33. position: relative;
  34. height: auto;
  35. -webkit-box-sizing: border-box;
  36. -moz-box-sizing: border-box;
  37. box-sizing: border-box;
  38. padding: 10px;
  39. font-size: 16px;
  40. }
  41. .form-signin .form-control:focus {
  42. z-index: 2;
  43. }
  44. .form-signin input[type="email"] {
  45. margin-bottom: -1px;
  46. border-bottom-right-radius: 0;
  47. border-bottom-left-radius: 0;
  48. border-color:#017572;
  49. }
  50. .form-signin input[type="password"] {
  51. margin-bottom: 10px;
  52. border-top-left-radius: 0;
  53. border-top-right-radius: 0;
  54. border-color:#017572;
  55. }
  56. h2{
  57. text-align: center;
  58. color: #017572;
  59. }
  60. </style>
  61. </head>
  62. <body>
  63. <h2>Enter Username and Password</h2>
  64. <div class = "container form-signin">
  65. <?php
  66. $msg = '';
  67. if (isset($_POST['login']) && !empty($_POST['username'])
  68. && !empty($_POST['password'])) {
  69. if ($_POST['username'] == 'tutorialspoint' &&
  70. $_POST['password'] == '1234') {
  71. $_SESSION['valid'] = true;
  72. $_SESSION['timeout'] = time();
  73. $_SESSION['username'] = 'tutorialspoint';
  74. echo 'You have entered valid use name and password';
  75. }else {
  76. $msg = 'Wrong username or password';
  77. }
  78. }
  79. ?>
  80. </div> <!-- /container -->
  81. <div class = "container">
  82. <form class = "form-signin" role = "form"
  83. action = "<?php echo htmlspecialchars($_SERVER['PHP_SELF']);
  84. ?>" method = "post">
  85. <h4 class = "form-signin-heading"><?php echo $msg; ?></h4>
  86. <input type = "text" class = "form-control"
  87. name = "username" placeholder = "username = tutorialspoint"
  88. required autofocus></br>
  89. <input type = "password" class = "form-control"
  90. name = "password" placeholder = "password = 1234" required>
  91. <button class = "btn btn-lg btn-primary btn-block" type = "submit"
  92. name = "login">Login</button>
  93. </form>
  94. Click here to clean <a href = "logout.php" tite = "Logout">Session.
  95. </div>
  96. </body>
  97. </html>

comments powered by Disqus