eventmanager/login.php

49 lines
1.3 KiB
PHP

<?php
session_start();
if ((!isset($_POST['login'])) || (!isset($_POST['haslo'])))
{
header('Location: index.php');
exit();
}
$login = $_POST['login'];
$haslo = $_POST['haslo'];
require_once "dbconnect.php";
$polaczenie = mysqli_connect($host, $db_user, $db_password);
mysqli_query($polaczenie, "SET CHARSET utf8");
mysqli_query($polaczenie, "SET NAMES 'utf8' COLLATE 'utf8_polish_ci'");
mysqli_select_db($polaczenie, $db_name);
$zapytanie = "SELECT * FROM users WHERE employeeID='".$login."' AND password='".$haslo."'";
$rezultat = mysqli_query($polaczenie, $zapytanie);
$ilu_userow = mysqli_num_rows($rezultat);
#$ilu_userow = $rezultat->num_rows;
if($ilu_userow>0)
{
$_SESSION['zalogowany'] = true;
$wiersz = $rezultat->fetch_assoc();
$_SESSION['employeeID'] = $wiersz['employeeID'];
$_SESSION['name'] = $wiersz['name'];
$_SESSION['surnname'] = $wiersz['surnname'];
$_SESSION['login'] = $_SESSION['employeeID'];
$_SESSION['perm'] = $wiersz['perm'];
unset($_SESSION['blad']);
$rezultat->free_result();
header('Location: index.php');
} else {
$_SESSION['blad'] = '<span style="color:red">Nieprawidłowy login lub hasło!</span>';
header('Location: login_page.php');
}
$polaczenie->close();
?>