-
Notifications
You must be signed in to change notification settings - Fork 1
/
login.php
57 lines (44 loc) · 1.72 KB
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
require_once('functions.php');
require_once('data.php');
session_start();
$page_name = 'Вход на сайт Yeticave';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$form = $_POST;
$required = ['email', 'password'];
$errors = [];
foreach ($required as $field) {
if (empty($form[$field])) {
$errors[$field] = 'Это поле надо заполнить';
}
}
$email = mysqli_real_escape_string($con, $form['email']);
$sql = "SELECT * FROM users WHERE email = '$email'";
$res = mysqli_query($con, $sql);
$user = $res ? mysqli_fetch_array($res, MYSQLI_ASSOC) : null;
if (!count($errors) && $user) {
if (password_verify($form['password'], $user['password'])) {
$_SESSION['user'] = $user;
} else {
$errors['password'] = 'Неверный пароль';
}
} else {
$errors['email'] = 'Такой пользователь не найден';
}
if (count($errors)) {
$page_content = include_template('login.php', ['form' => $form, 'errors' => $errors, 'categories' => $categories_query_array]);
} else {
header("Location: /index.php?page=1");
exit();
}
} else {
if (isset($_SESSION['user'])) {
$page_content = include_template('index.php', ['username' => $_SESSION['user']['name'],
'categories' => $categories_query_array, 'adverts' => $newlots_query_array]);
} else {
$page_content = include_template('login.php', ['categories' => $categories_query_array]);
}
}
$layout_content = include_template('layout.php', ['page_content' => $page_content,
'categories' => $categories_query_array, 'page_name' => $page_name]);
print($layout_content);