Advertisement
Guest User

index

a guest
Mar 11th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.85 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'php_action/db_connect.php';
  4. // agar tidak bisa keluar selain melalui logout
  5. session_start();
  6.  
  7. if(!isset($_SESSION['userId'])) {
  8.   header('location: http://localhost/stock_system/dashboard.php');
  9. }
  10.  
  11. $errors = array();
  12.  
  13. if($_POST) {
  14.  
  15.     $username = $_POST['username'];
  16.   $password = $_POST['password'];
  17.  
  18.   if(empty($username) || empty($password)) {
  19.     if($username == "") {
  20.       $errors[] = "Dibutuhkan Username";
  21.      }
  22.  
  23.      if($password == "") {
  24.       $errors[] = "Dibutuhkan Password ";
  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.         $_SESSION['login'] = TRUE;
  44.  
  45.         header('location: http://localhost/stock_system/dashboard.php');
  46.       } else{
  47.         $errors[] = "username tidak benar / password tidak benar";
  48.       }
  49.     } else {
  50.       $errors[] = "username tidak ada";
  51.     }
  52.  
  53.   }
  54. }
  55.  
  56.  ?>
  57.  
  58.  <!DOCTYPE html>
  59.  <html>
  60.  <head>
  61.     <title>Stock Management System</title>
  62.      <!--bootstrap -->
  63.      <link rel="stylesheet" type="text/css" href="assets/bootstrap/css/bootstrap.min.css">
  64.      <!-- bootstrap theme -->
  65.      <link rel="stylesheet" type="text/css" href="assets/bootstrap/css/bootstrap-theme.min.css">
  66.      <!-- font-awesome -->
  67.      <link rel="stylesheet" type="text/css" href="assets/font-awesome/css/font-awesome.min.css">
  68.      <!-- custom css-->
  69.      <link rel="stylesheet" type="text/css" href="custom/css/custom.css">
  70.      <!-- jquery -->
  71.      <script type="text/javascript" src="assets/jquery/jquery.min.js"></script>
  72.      <!--jqueryui -->
  73.       <link rel="stylesheet" type="text/css" href="assets/jquery-ui/jquery-ui.min.css">
  74.       <script type="text/javascript" src="assets/jquery-ui/jquery-ui.min.js"></script>
  75.      <!--bootstrapjs-->
  76.      <script type="text/javascript" src="assets/bootstrap/js/bootstrap.min.js"></script>
  77.  
  78.  </head>
  79.  <body>
  80.     <div class="container">
  81.       <div class="row vertical">
  82.         <div class="col-md-5 col-md-offset-4">
  83.         <div class="panel panel-info">
  84.         <div class="panel-heading">
  85.             <h3 class="panel-title">Silahkan masuk</h3>
  86.         </div>
  87.  
  88.         <div class="panel-body">
  89.           <div class="messages">
  90.             <?php if($errors) {
  91.               foreach ($errors as $key => $value) {
  92.                 echo '<div class="alert alert-warning" role="alert">
  93.                  <i class="glyphicon glyphicon-exclamation-sign"></i>
  94.                  '.$value.'</div>' ;
  95.               }
  96.             }
  97.               ?>
  98.             </div>
  99.  
  100.         <form class="form-horizontal" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST" ID="loginForm">
  101.   <div class="form-group">
  102.     <label for="username" class="col-sm-2 control-label">Username</label>
  103.     <div class="col-sm-10">
  104.       <input type="text" class="form-control" id="username" name="username" placeholder="username">
  105.     </div>
  106.   </div>
  107.   <div class="form-group">
  108.     <label for="password" class="col-sm-2 control-label">Password</label>
  109.     <div class="col-sm-10">
  110.       <input type="password" class="form-control" id="password" name="password" placeholder="Password">
  111.     </div>
  112.   </div>
  113.   <div class="form-group">
  114.     <div class="col-sm-offset-2 col-sm-10">
  115.       <button type="submit" class="btn btn-default"> <i class="glyphicon glyphicon-log-in"></i>Sign in</button>
  116.     </div>
  117.   </div>
  118. </form>
  119.         </div>
  120.         </div>
  121.         </div>
  122.         <!--col-md-5 -->
  123.       </div>
  124.       <!-- /row -->
  125.     </div>
  126.     <!-- /container -->
  127.  </body>
  128.  </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement