Guest User

Untitled

a guest
Apr 9th, 2018
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.96 KB | None | 0 0
  1. <?php # - main.php
  2.  
  3. if (!defined('BASE_URL')) {
  4.  
  5.   // Need the BASE_URL, defined in the config file:
  6.   require_once('../includes/config.php');
  7.  
  8.   // Redirect to index page:
  9.   $url = BASE_URL . 'index.php';
  10.   header ("Location: $url");
  11.   exit;
  12.  
  13. } // IF (!defined('BASE_URL'))
  14.  
  15. ?>
  16.     <?php
  17.             if (isset($_POST['login_submit'])) {
  18.  
  19.                 //echo "<pre>", print_r($_POST), "</pre>";
  20.  
  21.                 $username = mysqli_real_escape_string($db, $_POST ['username']);
  22.                 $password = mysqli_real_escape_string($db, $_POST['password']);
  23.  
  24.                 $errors = []; // betyder at det er et array()
  25.  
  26.                 if ($username == "") {
  27.                     $errors['username'] = "Brugernavn skal udfyldes";
  28.                 }
  29.  
  30.                 if ($password == "") {
  31.                     $errors['password'] = "Password skal udfyldes";
  32.                 }
  33.  
  34.                 if (empty($errors)) {
  35.  
  36.                     $sql = "SELECT * FROM users WHERE username = '$username'";  
  37.                     $result = mysqli_query($db, $sql);
  38.  
  39.                        if(mysqli_num_rows($result) > 0) {  
  40.                             while($row = mysqli_fetch_array($result)) {  
  41.                                  if(password_verify($password, $row["password"])) {  
  42.                                     //return true;  
  43.                                     $_SESSION['user_id'] = $user_id;
  44.                                     $_SESSION['username'] = $username;  
  45.                                     header("location: ../admin/");  
  46.                                  }  
  47.                                  else  
  48.                                  {  
  49.                                     //return false;  
  50.                                     $login_error = "Brugernavn eller adgangskode er forkert.";  
  51.                                  }  
  52.                             }  
  53.                        }  
  54.                        else  
  55.                        {  
  56.                             $login_error = "Brugernavn eller adgangskode er forkert.";  
  57.                        }
  58.  
  59.                 }
  60.  
  61.             }
  62.  
  63.         ?>
  64.  
  65.         <div class="top-content">
  66.             <div class="inner-bg">
  67.                 <div class="container">
  68.                     <div class="row">
  69.                         <div class="col-sm-6 col-sm-offset-3 form-box">
  70.                             <div class="form-top">
  71.                                 <div class="form-top-left">
  72.                                     <p><a href="../index.php"><i class="fa fa-arrow-circle-left" aria-hidden="true"></i> Tilbage</a></p>
  73.                                     <h3>Log ind til Admin Panelet</h3>
  74.                                     <p>Indtast dit brugernavn og adgangskode for at log ind:</p>
  75.                                 </div>
  76.                                 <div class="form-top-right">
  77.                                     <i class="fa fa-lock"></i>
  78.                                 </div>
  79.                             </div>
  80.                             <div class="form-bottom">
  81.                                 <?php
  82.                                     if (isset($login_error)) {
  83.                                         echo "<p> $login_error </p>";
  84.                                     }
  85.                                 ?>
  86.                                 <form role="form" action="?p=main" method="post" class="login-form">
  87.                                     <?php
  88.                                         if (isset($errors['username'])) {
  89.                                              echo $errors['username'];                            
  90.                                         }
  91.                                     ?>
  92.                                     <div class="form-group">
  93.                                         <label class="sr-only" for="username">Username</label>
  94.                                         <input type="text" name="username" placeholder="Username..." class="form-control" id="username">
  95.                                     </div>
  96.                                     <?php
  97.                                         if (isset($errors['password'])) {
  98.                                              echo $errors['password'];                            
  99.                                         }
  100.                                     ?>
  101.                                     <div class="form-group">
  102.                                         <label class="sr-only" for="password">Password</label>
  103.                                         <input type="password" name="password" placeholder="Password..." class="form-control" id="password">
  104.                                     </div>
  105.                                     <button type="submit" name="login_submit" class="btn">Log ind</button>
  106.                                 </form>
  107.                             </div>
  108.                         </div>
  109.                     </div>
  110.                 </div>
  111.             </div>
  112.         </div>
Add Comment
Please, Sign In to add comment