<?php
include_once 'sys/db.php';
include_once 'sys/fnc.php';
include_once 'sys/head.php';
if (isset($user)) header('Location: /');
if (isset($_POST['submit'])) {
$login = mysql_real_escape_string($_POST['login']);
$password = mysql_query("SELECT `pass` FROM `user` WHERE `login` = '$login' LIMIT 1");
if (mysql_num_rows($password) == 1) {
$pass = mysql_real_escape_string($_POST['pass']);
$user = mysql_query("SELECT `id` FROM `user` WHERE `login` = '$login' AND `pass` = '$pass' LIMIT 1");
if (mysql_num_rows($user) == 1) {
header("Location: /");
setcookie('login', $login, time()+60*60*24*14);
setcookie('pass', $pass, time()+60*60*24*14);
$_SESSION['user_id'] = $user['id'];
exit;
} else {
echo '<div class="err">Неправильный логин или пароль.</div>';
    }
} else {
echo '<div class="err">Неправильный логин или пароль.</div>';
}
            }
echo '<div class="title">Вход</div>';
if (!isset($_SESSION['user_id'])) {
        echo '<form class="menu" method="post">
        Логин: <br><input type="text" name="login" />
        <br>Пароль: <br>
        <input type="password" name="pass" />
        <br><input class="btn btn-default" type="submit" name="submit" value="Войти" />
        </form>';
}
include_once 'sys/foot.php';
?>