<?
session_start();


if ($_POST['username']) {

require('funciones.php');
$username=uc($_POST['username']);
$password=uc($_POST['password']);

if ($password==NULL) {
echo "неверный логин.";
}else{
require('config.php');
$query = mysql_query("SELECT username,password FROM tb_users WHERE username = '$username'") or die(mysql_error());
$data = mysql_fetch_array($query);
if($data['password'] != $password) {
echo "неверный логин.";
}else{
$query = mysql_query("SELECT username,password FROM tb_users WHERE username = '$username'") or die(mysql_error());
$row = mysql_fetch_array($query);
mysql_close($con);
$nicke=$row['username'];
$passe=$row['password'];

setcookie("usNick",$nicke,time()+7776000);
setcookie("usPass",$passe,time()+7776000);

$lastlogdate=date("Y-m-d h:i:s");
$lastip = getRealIP();
require('config.php');
$querybt = "UPDATE tb_users SET lastlogdate='$lastlogdate', lastiplog='$lastip' WHERE username='$nicke'";
mysql_query($querybt) or die(mysql_error());
mysql_close($con);

?>

<META HTTP-EQUIV="REFRESH" CONTENT="0;URL=work.php">

<?
}
}
}else{
?>
<? include('header.php'); ?>

								<div class="content_top_center">
									<div class="content_top_left">
										<div class="content_top_right">
			
			<table class="contentpaneopen"><tr><td class="contentheading" width="100%">Авторизация</td></tr></table>
			
		<table class="contentpaneopen"><tr><td width="70%" align="left" valign="top" colspan="2"><span class="small"></td></tr>
			<tr>
				<td valign="top" colspan="2" class="createdate"></td>
			</tr>
</table>

		              </div>
									</div>
								</div>

<a href="register.php">Регистрация</a>
<br><br>


<div align="center"><div id="form">
<form action='login.php' method='POST'>

<table width="400" border="0" align="center">
  <tr>
    <td width="150" align="left"><p><label>Имя</label></p></td>
    <td width="250" align="left"><input type='text' size='15' maxlength='25' name='username' autocomplete="off"value="" tabindex="1" /></td>
  </tr>
  <tr>
    <td width="150" align="left"><p><label>Пароль</label></p></td>
	<td width="250" align="left"><input type='password' size='15' maxlength='25' name='password' autocomplete="off" value="" tabindex="2" /></td>
  </tr>


  <tr>
    <td width="150" align="left">&nbsp;</td>
    <td width="250" align="right"><input type="image" src="images/btn_voiti.gif" value="Войти" class="submit"/>
	</td>
  </tr>
</table>
</form>
</div></div>





<? include('footer.php'); ?>
<?
}
?>
