Advertisement
Guest User

Untitled

a guest
Oct 4th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. <?php
  2. require_once 'php_action/db_connect.php';
  3. session_start();
  4.  
  5. if(isset($_SESSION['userId'])) {
  6. header('location: http://localhost/managementsystem/dashboard.php');
  7. }
  8.  
  9. $errors = array();
  10.  
  11. if($_POST) {
  12. $username = $_POST['username'];
  13. $password = $_POST['password'];
  14.  
  15.  
  16.  
  17.  
  18. if(empty($username) || empty($password)) {
  19. if($username == "") {
  20. $errors[] = "Username is required";
  21. }
  22.  
  23. if($password == "") {
  24. $errors[] = "Password is required";
  25. }
  26. }else{
  27. $sql = "SELECT * FROM users WHERE username = '$username'";
  28. $result = $connect->query($sql);
  29.  
  30. if($result->num_rows == 1) {
  31. $password = md5($password);
  32. // exists
  33. $mainSql = "SELECT * FROM users WHERE username = '$username' AND password='$password'";
  34. $mainResult = $connect->query($mainSql);
  35.  
  36. if($mainResult->num_rows == 1) {
  37. $value = $mainResult->fetch_assoc();
  38. $user_id = $value['user_id'];
  39.  
  40. //set session
  41. $_SESSION['userId'] = $user_id;
  42.  
  43. header('location: http://localhost/managementsystem/dashboard.php');
  44. } else {
  45. $errors[] = "Incorrect Username or Password combination";
  46. }
  47. }else {
  48. $errors[] = "Username does not exists";
  49. }
  50. }
  51. }
  52. ?>
  53.  
  54. <!DOCTYPE html>
  55. <html>
  56. <head>
  57. <title>Log-in Page</title>
  58. <!-- bootstrap -->
  59. <link rel="stylesheet" type="text/css" href="assets/bootstrap/css/bootstrap.min.css">
  60. <!-- bootstrap theme -->
  61. <link rel="stylesheet" type="text/css" href="assets/bootstrap/css/bootstrap-theme.min.css">
  62. <!-- font awesome -->
  63. <link rel="stylesheet" type="text/css" href="assets/font-awesome/css/font-awesome.min.css">
  64. <!-- custom css -->
  65. <link rel="stylesheet" href="custom/css/custom.css">
  66. <!-- jquery -->
  67. <script type="text/javascript" src="assets/jquery/jquery.min.js"></script>
  68. <!-- jquery ui -->
  69. <link rel="stylesheet" href="assets/jquery-ui/jquery-ui.min.css">
  70. <script src="assets/jquery-ui/jquery-ui.min.js"></script>
  71. <!-- bootstrap js -->
  72. <script src="assets/bootstrap/js/bootstrap.min.js"></script>
  73. </head>
  74. <body>
  75.  
  76. <div class="container">
  77. <div class="row vertical">
  78. <div class="col-md-5 col-md-offset-3">
  79. <div class="panel panel-default">
  80. <div class="panel-info">
  81. <div class= "panel-heading text-center">
  82. <h3 class= "panel-title">MH ALLIM Management System</h3>
  83. </div>
  84. <div class="panel-body">
  85.  
  86. <div class="messages">
  87. <?php if($errors) {
  88. foreach ($errors as $key => $value) {
  89. echo '<div class="alert alert-warning" role="alert">
  90. <i class="glyphicon glyphicon-exclamation-sign"></i>
  91. '.$value.'</div>';
  92. }
  93. } ?>
  94. </div>
  95.  
  96. <form class="form-horizontal" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST" id="loginForm">
  97. <div class="form-group">
  98. <label for="inputUser3" class="col-sm-2 control-label">Username</label>
  99. <div class="col-sm-10">
  100. <input type="text" class="form-control" id="username" name="username" placeholder="Username">
  101. </div>
  102. </div>
  103. <div class="form-group">
  104. <label for="password" class="col-sm-2 control-label">Password</label>
  105. <div class="col-sm-10">
  106. <input type="password" class="form-control" id="password" name="password" placeholder="Password">
  107. </div>
  108. </div>
  109. <div class="form-group">
  110. <div class="col-sm-offset-2 col-sm-10">
  111. <button type="submit" class="btn btn-default"> <i class="glyphicon glyphicon-log-in"></i>
  112. Sign in</button>
  113. </div>
  114. </div>
  115. </form>
  116.  
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123.  
  124. </body>
  125. </html>
  126.  
  127. <?php
  128.  
  129. session_start();
  130.  
  131. require_once 'db_connect.php';
  132.  
  133. //echo $_SESSION['userId'];
  134.  
  135. if(!$_SESSION['userId']){
  136. header('location: http://localhost/managementsystem/index.php');
  137. }
  138.  
  139. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement