Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.53 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. if ((!isset($_POST['login'])) || (!isset($_POST['password'])))
  5. {
  6.     header('Location: index.php');
  7.     exit();
  8. }
  9. require_once "dbconnect.php";
  10.  
  11. $connection = @new mysqli($host, $db_user, $db_password, $db_name);
  12.  
  13. if ($connection->connect_errno!=0)
  14. {
  15.     echo "Error:".$connection->connect_errno;
  16. }
  17. else
  18. {
  19.     $login = $_POST['login'];
  20.     $password = $_POST['password'];
  21.    
  22.     $login = htmlentities($login,ENT_QUOTES, "UTF-8");
  23.    
  24.     //zabezpieczenie logowania
  25.     if ($result = @$connection->query(sprintf("SELECT * FROM user WHERE user='%s'",
  26.     mysqli_real_escape_string($connection,$login))))
  27.     {
  28.         $how_much_users = $result->num_rows;
  29.         if($how_much_users>0)
  30.         {
  31.            
  32.             $row = $result->fetch_assoc();
  33.             if(password_verify($password,$row['pass']))
  34.             {
  35.  
  36.                 $_SESSION['logged'] = true;
  37.                 $_SESSION['userID'] = $row['userID'];
  38.                 $_SESSION['user'] = $row['user'];
  39.                 $_SESSION['mail'] = $row['mail'];
  40.  
  41.                 unset($_SESSION['error']);
  42.                 $result->close();
  43.                 header('Location: main.php');
  44.             }
  45.             else
  46.             {
  47.                 $_SESSION['error'] = '<span style="color:red">Nieprawidłowy login lub hasło!</span>';
  48.                 header('Location: log.php');
  49.             }
  50.         }
  51.         else
  52.         {
  53.             $_SESSION['error'] = '<span style="color:red">Nieprawidłowy login lub hasło!</span>';
  54.             header('Location: log.php');
  55.         }
  56.     }
  57.     $connection->close();
  58. }
  59.  
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement