<?php
    session_start();
    $login= trim($_POST['login']);
    $password = trim($_POST['password']);
	
	    include "settings.php";
        $db = new mysqli ($DB_HOST,$DB_USER,$DB_PASS,$DB_NAME);
        $db->query("SET CHARSET SET utf8");
        $db->query("SET NAMES 'utf8'");
        if (mysqli_connect_errno()) {
            //echo "Error connecting to DB";
            exit;
        }
	
	
    
    $is_bloked = "";
    //if ($login!='')
    if (($login || $login!='') && ($password || $password!='')) {
        if (!get_magic_quotes_gpc()){
            $login = addslashes($login);
            $password = addslashes ($password);
			//$password = md5($password);
        }
        
       
        $query = "SELECT COUNT(`id`), `id`, login, id_role FROM ms_user WHERE (login='".$login."' AND password='".md5($password)."')";
		if ($stmt = $db->prepare($query)){
        //$stmt->bind_param('ss',$login,md5($password));
        $stmt->execute();
        $stmt->bind_result($result, $id, $login, $id_role);
		 $stmt->fetch();
         $is_bloked = $bloked;
         //$stmt->close();
         if ($result > 0 ) {

            $_SESSION['id'] = $id;
            $_SESSION['login'] = $login;
            $_SESSION['id_role'] = $id_role;
			
			$URL = 'index.php';
            uf_redirect($URL);
		  
		
			
            exit;
        }
		
        
         
		 
		 $stmt->close();
		 $db->close();
		 }
    }
 
	
?>
