-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsign-up.php
More file actions
41 lines (32 loc) · 1.19 KB
/
sign-up.php
File metadata and controls
41 lines (32 loc) · 1.19 KB
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
<?php
/**
* Описание переменных
* @var mysqli $connection идентификатор соединения БД
* @var string $title заголовок страницы
*/
require_once __DIR__ . '/bootstrap.php';
if (isset($_SESSION['user'])) {
header('Location: /403.php');
}
$categories = get_categories($connection);
$errors = [];
$form_data = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$form_data = filter_form_fields($_POST);
$errors = validate_registration_form($connection, $form_data);
if (empty($errors)) {
$form_data['password'] = password_hash($form_data['password'], PASSWORD_DEFAULT);
add_user($connection, $form_data);
header("Location: /login.php");
}
}
$main_menu = include_template('/menu/menu.php', ['categories' => $categories]);
$main_page = include_template('sign-up.php', ['error' => $errors, 'form_data' => $form_data]);
$main_footer = include_template('footer.php', ['categories' => $categories, 'main_menu' => $main_menu]);
$layout_content = include_template('layout.php', [
'main_menu' => $main_menu,
'content' => $main_page,
'footer' => $main_footer,
'title' => $title
]);
print ($layout_content);