Advertisement
Guest User

login.php

a guest
Mar 10th, 2016
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.31 KB | None | 0 0
  1. <?php
  2. require_once $_SERVER['DOCUMENT_ROOT'].'/tutorial/core/init.php';
  3. include 'includes/head.php';
  4.  
  5. $email = ((isset($_POST['email']))?sanitize($_POST['email']):'');
  6. $email = trim($email);
  7. $password = ((isset($_POST['password']))?sanitize($_POST['password']):'');
  8. $password = trim($password);
  9. $errors = array();
  10. ?>
  11. <style type="text/css">
  12. body{
  13.     background-image : url("/tutorial/images/headerlogo/background.png");
  14.     background-size : 100vw 100vh;
  15.     background-attachment: fixed;
  16. }
  17. </style>
  18. <div id="login-form">
  19.     <div>
  20.  
  21.         <?php
  22.         if ($_POST) {
  23.  
  24.             # validasi Form
  25.             if (empty($_POST['email']) || empty($_POST['password'])) {
  26.                 $errors[] = 'Kolom email dan password harus diisi';
  27.             }
  28.  
  29.             # validasi email
  30.             if (!filter_var($email,FILTER_VALIDATE_EMAIL)) {
  31.                 $errors[] = 'Tolong ketikkan email yang valid';
  32.             }
  33.  
  34.             #jika password kurang dari 6
  35.             if (strlen($password) < 6) {
  36.                 $errors[] = 'Password tidak boleh kurang dari 6 huruf';
  37.             }
  38.  
  39.             # cek email jika sudah ada didalam database
  40.             $query = $db->query("SELECT * FROM users WHERE email = '$email'");
  41.             $user = mysqli_fetch_assoc($query);
  42.             $hitung = mysqli_num_rows($query);
  43.             if ($hitung < 1) {
  44.                 $errors[] = 'Email yang anda masukan salah!';
  45.             }
  46.  
  47.             if (!password_verify($password,$user['password'])) {
  48.                 $errors[] = 'Password yang anda masukan salah!';
  49.             }
  50.  
  51.             # cek kesalahan
  52.             if (!empty($errors)) {
  53.                 echo display_errors($errors);
  54.             }else{
  55.                 #jika semua verifikasi sudah dilewati
  56.                 $user_id = $user['id'];
  57.                 login($user_id);
  58.             }
  59.  
  60.         }
  61.         ?>
  62.  
  63.     </div>
  64.     <h2 class="text-center">Login</h2>
  65.     <form action="login.php" method="post">
  66.         <div class="form-group">
  67.             <label for="email">Email :</label>
  68.             <input type="text" name="email" class="form-control" id="email" value="<?=$email;?>">
  69.         </div>
  70.         <div class="form-group">
  71.             <label for="password">Password :</label>
  72.             <input type="password" name="password" class="form-control" id="password" value="<?=$password?>">
  73.         </div>
  74.         <div class="form-group">
  75.             <input type="submit" class="btn btn-primary" name="name" value="Login">
  76.         </div>
  77.     </form>
  78.     <p class="text-right"><a href="/tutorial/index.php">Visit Site</a></p>
  79. </div>
  80.  
  81. <footer class="text-center" id="footeristik">&copy; Copyright 2016 Shauntas's Boutique, Created By : Restu Haerul Z.</footer>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement