-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreg.php
62 lines (59 loc) · 2.5 KB
/
reg.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
56
57
58
59
60
61
62
<?php
$start_time = microtime(TRUE);
session_start();
$_SESSION['requests'] = 0;
$_SESSION['time'] = 0;
$_SESSION['socket_requests'] = 0;
$_SESSION['socket_time'] = 0;
$error = "";
if (isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
unset($_COOKIE['username']);
setcookie('username', null, -1, '/');
unset($_COOKIE['password']);
setcookie('password', null, -1, '/');
}
if (!empty($_POST)) {
if(isset($_POST['username']) && isset($_POST['password']) && $_POST['username'] != "" && $_POST['password'] != "") {
if(strpos($_POST['username'], "|")) {
$error = "Запрещённые символы в нике";
}
else {
$username = $_POST['username'];
$pass = $_POST['password'];
$con = new mysqli("127.0.0.1", "root", "root", "html_game");
$stmt = $con->prepare("INSERT INTO players (nickname, password, damage, hp, rating) VALUES ('" . $username . "', '" . $pass . "', '10', '100', '100')");
$_SESSION['requests']++;
if (!$stmt->execute()) {
$error = "Пользователь с этим ником уже существует!";
} else {
setcookie('username', $username);
setcookie('password', $pass);
header('Location: main.php');
}
}
}
else {
$error = "Заполните все поля!";
}
}
?>
<div class="main main-raised col-md-8 mx-auto my-5 text-center section" id="reg">
<h3 class="big-text disable-select">Регистрация</h3>
<form action="reg.php" method="POST" id="enter">
<input type="text" name="username" id="username" placeholder="Никнейм" /> <br /> <br />
<input type="password" name="password" id="password" placeholder="Пароль" /> <br /> <br />
<p class="text disable-select" style="color: red"><?=$error?></p>
<input type="submit" name="enter" value="Регистрация" />
</form>
<a href="/login.php">Вход</a>
</div>
<footer>
<link rel="stylesheet" href="css/material-kit.css"">
<link rel="stylesheet" href="css/menu.css"">
</footer>
<?php
$end_time = microtime(TRUE);
$time_taken = ($end_time - $start_time)*1000;
$time_taken = round($time_taken, 2);
echo '<p class="disable-select" style="text-align: center;">page: '.$time_taken.' ms, db: '.$_SESSION['requests'].'('.round($_SESSION['time'], 2).'), sockets: '.$_SESSION['socket_requests'].'('.round($_SESSION['socket_time'], 2).')</p>';
?>