<?php
include ('inc/base.php');
include ('inc/functions.php');
include ('inc/user.php');
$title = 'Авторизация';
include ('inc/header.php');
if($user) {
header('location: /');
exit();
}
if(isset($_POST['send'])) {
$name = text($_POST['name']);
$password = text($_POST['password']);
if(!$name or !$password) {
echo '<div class="main center">Заполните все поля!</div>';
echo '<a href="?" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if(strlen($name) < 2 or strlen($name) > 16) {
echo '<div class="main center">Допустимая длина ника 2-16 символов!</div>';
echo '<a href="?" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if(strlen($password) < 3 or strlen($password) > 18) {
echo '<div class="main center">Допустимая длина пароля 3-18 символов!</div>';
echo '<a href="?" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
$account = mysql_fetch_array(mysql_query('SELECT * FROM `accounts` WHERE `name` = "'.$name.'" and `password` = "'.$password.'" LIMIT 1'));
mysql_free_result($account);
if(!$account) {
$account2 = mysql_fetch_array(mysql_query('SELECT * FROM `accounts` WHERE `name` = "'.$name.'" and `secret_code` = "'.$password.'" LIMIT 1'));
mysql_free_result($account2);
}
if(!$account and !$account2) {
echo '<div class="main center">Указанные данные неверны!</div>';
echo '<a href="?" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($account) {
setCookie('user_id', $account['id'], time() + 86400 * 365, '/');
setCookie('password', $account['password'], time() + 86400 * 365, '/');
}
if($account2) {
setCookie('user_id', $account2['id'], time() + 86400 * 365, '/');
setCookie('password', $account2['password'], time() + 86400 * 365, '/');
}
echo '<div class="main center">Вы успешно авторизированы в игре!</div>';
echo '<a href="?" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
echo '<div class="main center"><img src="/style/src/logo.png" width="50%"></div>';
if(isset($_GET['re'])) {
echo '<div class="main center">Введите секретное слово в поле пароль чтобы войти на аккаунт!</div>';
}
echo '<form action="?" class="main center" method="POST"> Ник <br> <input type="text" name="name"> <br> Пароль <br> <input type="password" name="password"> <br> [<a href="?re" class="a2">не помню пароль</a>] <br> <input type="submit" class="input_send" name="send" value="Вперёд"></form><form action="/" class="main center" method="GET"><input type="submit" class="input_back" value="Назад"></form>';
include ('inc/footer.php');
?>