Advertisement
Guest User

zaloguj.php

a guest
Aug 28th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. <?php
  2.     session_start();
  3.  
  4.     if ((!isset($_POST['login'])) || (!isset($_POST['haslo'])))
  5.     {
  6.         header('Location: index.php');
  7.         exit();
  8.     }
  9.     require_once "connect.php";
  10.  
  11.     $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
  12.    
  13.     if ($polaczenie->connect_errno!=0)
  14.     {
  15.         echo "Error: ".$polaczenie->connect_errno;
  16.     }
  17.     else
  18.     {
  19.         $login = $_POST['login'];
  20.         $haslo = $_POST['haslo'];
  21.         $haslo_hash = hash("sha256", $_POST['haslo']);
  22.         $login = htmlentities($login, ENT_QUOTES, "UTF-8");
  23.         $haslo = htmlentities($haslo_hash, ENT_QUOTES, "UTF-8");
  24.    
  25.         echo mysql_error();
  26.          if ($rezultat = @$polaczenie->query(
  27.         sprintf("SELECT * FROM uzytkownicy WHERE user='%s' AND pass='%s'",
  28.         mysqli_real_escape_string($polaczenie,$login),
  29.         mysqli_real_escape_string($polaczenie,$haslo_hash))))
  30.         {
  31.             echo mysql_error();
  32.             $ilu_userow = $rezultat->num_rows;
  33.             if($ilu_userow>0)
  34.             {
  35.                 include"refresh.php";
  36.                
  37.                 unset($_SESSION['blad']);
  38.                 $rezultat->free_result();
  39.                 header('Location: main.php');
  40.                 echo mysql_error();
  41.                
  42.             }
  43.             else
  44.             {
  45.                 $_SESSION['blad'] = ' Nieprawidłowy login lub hasło! ';
  46.                 header('Location: index.php');
  47.                
  48.             }
  49.            
  50.         }
  51.         $polaczenie->close();
  52.     }
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement