<?php
require 'connect.php';
if(!isset($_COOKIE['id'])){
if (isset($_POST['submit'])) {
$login = $_POST['login'];
$pass = md5($_POST['pass']);
if(!empty($login) && !empty($pass)){
$query = "SELECT id
, name
, password
FROM best
WHERE name = '$login' AND password = '$pass'";
$result = mysqli_query($link, $query);
// print_r($result);
if (mysqli_num_rows($result) == 1) {
$row = mysqli_fetch_assoc($result);
setcookie('id', $row['id'], time() + (60*60) );
setcookie('name', $row['name'], time() + (60*60) );
header('Location: index.php');
}else{
echo "Введите правильный логин пароль";
}
}else{
echo "Заполните поля";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>
Авторизация
</title>
</head>
<body>
<style>
*{
margin: 10;
padding: 10;
}
.login{
text-align: center;
}
button{
border-color: black;
}
</style>
<div class="login">
<h1> Авторизация</h1>
<form method="POST">
<label>Ваш логин:</label>
<input type="text" name="login">
<br><br>
<label>Ваш пароль:</label>
<input type="password" name="pass">
<br><br>
<button type="submit" name="submit">Войти</button>
</form>
<!-- <a href="index.php">Главная</a> -->
</div>
</body>
</html>