<?php
 $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if(is_file ("lang/".$lang."/".$lang.".php")) include "lang/".$lang."/".$lang.".php";
     else include "lang/ru/ru.php";

  require_once "config.php";

  if(! @mysql_select_db($dbname,$dbcnx))
  {
    echo "<html>
            <head>
            <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
            <link rel='StyleSheet' type='text/css' href='skins/base/reader.css' />
            <link rel='icon' href='favicon.ico' type='image/x-icon' />
            <link rel='shortcut icon' href='favicon.ico' type='image/x-icon' />
            <title>".$TEXT['global-title']."</title>
            </head><body>
            <table align='center' border='0'><tr align='center'><td><img alt='stop' src='img/stop.png' /></td></tr><tr  align='center' ><td><span class='res'>".$TEXT['error-conf1']."</span></td></tr></table>
            </body></html>";
    exit();
  }

  if(empty($_POST['login'])) puterror("Login empty.");
  if(strlen($_POST['login'])>100) puterror("Login very long. Use maximum 100 chars.");
  if(strlen($_POST['password'])>100) puterror("Password very long. Use maximum 100 chars.");

  if(isset($_POST['login'])) $login=trim($_POST['login']);
    else $login="";
     if(empty($login)) puterror("Spaces do not approach at login...");

  if(isset($_POST['password'])) $password=trim($_POST['password']);
    else $password="";
     if(empty($password)) puterror("Spaces do not approach at password...");

//  $_POST['login'] = str_replace("'","`",$_POST['login']);
//  $_POST['password'] = str_replace("'","`",$_POST['password']);
//  $_POST['login'] = htmlspecialchars(stripslashes($_POST['login']));
//  $_POST['password'] = htmlspecialchars(stripslashes($_POST['password']));

  $_POST['login'] = rep($_POST['login']);
  $_POST['password'] = rep($_POST['password']);

  $query = "SELECT * FROM `tbl_logins` WHERE `login`='".$_POST['login']."' ";
  $result = mysql_query($query);
  if(!$result) puterror("Error login checking...");
      $result2 = mysql_fetch_array($result);
      $login = $_POST['login'];
      $ident = $result2['login_id'];
      $passwrd = md5($_POST['password']);
     if($passwrd == $result2['pass'])
     {
       setcookie("login", $login, time()+3600*8);
       setcookie("passwrd", $passwrd, time()+3600*8);
       setcookie("ident", $ident, time()+3600*8);

       echo "<html><head>
             <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=zayavka_otv.php' />
             </head></html>";
     }
     else puterror($TEXT['error-loginform3']);
?>