<?php
session_start();
include_once "inc/db_connect.php";
header('Content-Type: text/html;charset=utf8');
$err = "";
if(isset($_POST['regok'])){unset($_SESSION['reg_ok']);}
if(isset($_SESSION['user'])){
include "garage.php";
	exit();
}else{
if(isset($_POST['submit']))
{
	$rand=rand(1,3);
	$nick = mysql_real_escape_string(strip_tags(stripslashes(htmlspecialchars($_POST['nick']))));
	$pass = mysql_real_escape_string(strip_tags(stripslashes(htmlspecialchars(trim($_POST['pass'])))));
	$query_us = mysql_query("SELECT id,nick,password FROM users WHERE nick ='{$nick}' AND password='{$pass}' LIMIT 1") or die(mysql_error());
	if(mysql_num_rows($query_us) == 1){
		$_SESSION['user'] = $nick;
		header("Location: index.php?");
		exit();
	}else{
		$err = "Неверный ник или пароль";
	}
	if($pass == "") {$err = "Введите пароль";}
	if($nick == "") { $err = "Введите ник";}
}
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
echo '<html>';
echo '<head>';
echo '<title>Лига скорости</title>';
	echo '<meta http-equiv="Content-Type" content="text/html" charset="windows-1251" />';
	echo '<meta name="description" content="Мобильные онлайн гонки">';
	echo '<link rel="stylesheet" type="text/css" href="/style/default/mobile.css" />';
echo '</head>';
echo '<body>';
?>
<?php
 if($err) echo "<div class='err'>" , $err , "</div>";?>
</div>
<center><img src="/img/logo.png" alt="Логотип" width="200" height="130"/><br><br><b><font size='4'>Лига Скорости</font></b></center><br>
<div class="title">
<center>AvtoGame.com</center>
</div>
<div class="mono">
<center>
<form action="<?=$_SERVER["PHP_SELF"]?>" method="post">
<font color="#0769ad"><b>Введите ваш ник:</b> </font><br /><input class="input" type="text" name="nick" value="" /><br />
<font color="#0769ad"><b>Введите ваш пароль:</b> </font><br /><input class="input" type="password" name="pass" value="" /><br />
<input type="submit" name="submit" value="Играть" class="btn" />
</form>
</center>
</div>
<div class="menu">
<center><a href="/rules.php" title="Правила"><font color="#0769ad"><b>Правила Игры</b></font></a></center>
</div>
<table class="menu1 wdt">
	<tr>
<td><a href="/reg.php" title="Регистрация"><font color="#0769ad">Регистрация</font></a></td>
	</tr>
</table>
<div class="karo"><center><?php echo 'Гонщиков: <b>'.mysql_result(mysql_query("SELECT COUNT(*) FROM `users`"), 0).'</b>'; ?></center></div>
<div class="title">
<p>&copy; Лига скорости <?=date("Y")?></p>
</div>
</body>
</html>
<?
}
?>