Advertisement
myarkqub

login - index.php

Aug 11th, 2019
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. <?php
  2.     $conn = mysqli_connect("127.0.0.1", "root", "123123", "login");
  3.     if(!$conn){
  4.         echo "database connection error";
  5.     }
  6.    
  7.     session_start();
  8.    
  9.     if(isset($_POST["login"])){
  10.         $username = mysqli_real_escape_string($conn, $_POST["username"]);
  11.         $password = mysqli_real_escape_string($conn, $_POST["password"]);
  12.        
  13.         $check_username = mysqli_num_rows(mysqli_query($conn, "SELECT null FROM users WHERE username = '$username'"));
  14.         if($check_username == 0){
  15.             echo "Username not exist";
  16.         }
  17.         else{
  18.             $user_info = mysqli_fetch_assoc(mysqli_query($conn, "SELECT id, password FROM users WHERE username = '$username'"));
  19.             if(password_verify($password, $user_info["password"])){
  20.                 $_SESSION["id"] = $user_info["id"];
  21.                 header("Location: home.php");
  22.             }
  23.             else{
  24.                 echo "Password incorrect";
  25.             }
  26.         }
  27.     }
  28.    
  29. ?>
  30.  
  31. <form method="post">
  32.     Username: <input name="username" type="text"><br>
  33.     Password: <input name="password" type="password"><br>
  34.     <button name="login" type="submit">Login</button>
  35. </form>
  36.  
  37. <a href="register.php">Register</a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement