Файл: user/login.php
Строк: 50
<?php
/* DCMS S (Special)
* Версия файла 0.0.1
* Дата последнего редактирования 19.11.2015
* Модифицировал densnet
*/
require_once '../sys/inc/start.php';
require_once H . 'sys/inc/compress.php';
require_once H . 'sys/inc/sess.php';
require_once H . 'sys/inc/settings.php';
require_once H . 'sys/inc/db_connect.php';
require_once H . 'sys/inc/ipua.php';
require_once H . 'sys/inc/fnc.php';
require_once H . 'sys/inc/shif.php';
$show_all = true; // показ для всех
$input_page = true;
require_once H . 'sys/inc/user.php';
only_unreg();
if (isset($_GET['id']) && isset($_GET['pass'])) {
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '" . intval($_GET['id']) . "' AND `pass` = '" . shif($_GET['pass']) . "' LIMIT 1"), 0) == 1) {
$user = get_user($_GET['id']);
$_SESSION['id_user'] = $user['id'];
mysql_query("UPDATE `user` SET `date_aut` = " . time() . " , `date_last` = " . time() . " WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("INSERT INTO `user_log` (`id_user`, `time`, `ua`, `ip`, `method`) values('$user[id]', '$time', '$user[ua]' , '$user[ip]', '0')");
} else {
$err[] = 'Неправильный логин или пароль';
}
} elseif (isset($_POST['nick']) && isset($_POST['pass'])) {
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `nick` = '" . mysql_real_escape_string($_POST['nick']) . "' AND `pass` = '" . shif($_POST['pass']) . "' LIMIT 1"), 0)) {
$user = mysql_fetch_assoc(mysql_query("SELECT `id` FROM `user` WHERE `nick` = '" . mysql_real_escape_string($_POST['nick']) . "' AND `pass` = '" . shif($_POST['pass']) . "' LIMIT 1"));
$_SESSION['id_user'] = $user['id'];
$user = get_user($user['id']);
mysql_query("INSERT INTO `user_log` (`id_user`, `time`, `ua`, `ip`, `method`) values('$user[id]', '$time', '$user[ua]' , '$user[ip]', '1')");
# сохранение данных в COOKIE
if (isset($_POST['aut_save']) && $_POST['aut_save']) {
setcookie('id_user', $user['id'], time() + 60 * 60 * 24 * 365);
setcookie('pass', cookie_encrypt($_POST['pass'], $user['id']), time() + 60 * 60 * 24 * 365);
}
} else {
$err[] = 'Неправильный логин или пароль';
}
} elseif (isset($_COOKIE['id_user']) && isset($_COOKIE['pass']) && $_COOKIE['id_user'] && $_COOKIE['pass']) {
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = " . intval($_COOKIE['id_user']) . " AND `pass` = '" . shif(cookie_decrypt($_COOKIE['pass'], intval($_COOKIE['id_user']))) . "' LIMIT 1"), 0) == 1) {
$user = get_user($_COOKIE['id_user']);
$_SESSION['id_user'] = $user['id'];
mysql_query("UPDATE `user` SET `date_aut` = '$time', `date_last` = '$time' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("INSERT INTO `user_log` (`id_user`, `time`, `ua`, `ip`, `method`) values('$user[id]', '$time', '$user[ua]' , '$user[ip]', '2')");
$user['type_input'] = 'cookie';
} else {
$err[] = 'Ошибка авторизации по COOKIE';
setcookie('id_user');
setcookie('pass');
}
} else {
$err[] = 'Ошибка авторизации';
}
if (!isset($user)) {
$set['title'] = 'Авторизация';
require_once H . 'sys/inc/thead.php';
aut();
err();
echo "<div class='list-group-item'>";
echo "<a href='/user/aut.php'><span class='fa fa-arrow-left fa-fw'></span> Повторить попытку входа</a>";
echo "</div>";
require_once H . 'sys/inc/tfoot.php';
}
if (isset($_GET['return'])) {
header('Location: ' . urldecode($_GET['return']));
} else {
header("Location: /?" . SID);
}
exit;