<?php
include('../inc/conf.php');
ini_set('session.use_cookies', 'On');
ini_set('session.use_trans_sid', 'Off');
session_set_cookie_params(604800000, "/", SITE, false, false);
session_start();
if (isset($_SESSION["uid"])){ echo "4"; exit; }
if(isset($_POST['login']) && isset($_POST['pass'])){
if (!empty($_POST['login']) && !empty($_POST['pass'])) {
$dt = time();
$pdt = $dt + 300;
$ip = $_SERVER['REMOTE_ADDR'];
$login = mysqli_real_escape_string($connect_db, $_POST['login']);
$pass = mysqli_real_escape_string($connect_db, $_POST['pass']);
$user = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT uid,log,pas FROM t_users WHERE log='$login' AND pas='$pass';"));
$c = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT c FROM t_login WHERE ip='$ip'"));
$count = intval($c['c']);
if ($count > 10) { if ($count < $dt) { mysqli_query($connect_db, "UPDATE `t_login` SET `c` = '1' WHERE ip='$ip'"); $count = '1'; } else { echo '2'; exit; } }
if(!empty($user)) {
mysqli_query($connect_db, "DELETE FROM t_login WHERE ip='$ip'");
session_unset();
$_SESSION['uid']=$user['uid'];
$_SESSION['login']=$user['log'];
$_SESSION['pass']=$user['pas'];
mysqli_query($connect_db, "UPDATE `t_users` SET `last` = '$dt' WHERE uid = '$user[uid]'");
echo '1';
} else {
if ($count == 0) { mysqli_query($connect_db, "INSERT INTO `t_login` (ip,c) VALUES ('$ip','1')"); }
if ($count > 0 && $count < 10) { mysqli_query($connect_db, "UPDATE `t_login` SET `c` = `c`+1 WHERE ip='$ip'"); }
if ($count == 10) { mysqli_query($connect_db, "UPDATE `t_login` SET `c` = '$pdt'"); }
echo '0';
}
} else { echo '3'; }
} else { echo '3'; }
?>