<?php 
require "inc/commonfunctions.php";

 // THIS SHOULD BE THE VERY FIRST LINES OF CODE IN YOUR SCRIPTS
    if (session_status() == PHP_SESSION_NONE  || session_id() == '') {
        session_start();
		//echo session_id();
		//print_r($_SESSION);
    }	
 
	
	$Error=0;        
   
    if(!isset($_SESSION["UserNameSession"]))
    {
        if(!isset($_SESSION['6_letters_captcha']) || strcasecmp($_SESSION['6_letters_captcha'],$_POST['captcha']) != 0)
		{
            
            $Error=2;	
			$_SESSION['_err']=$Error;
            echo "{success:'false',error:'".$Error."'}";						
		}
        else
        {           
            $username = $_POST['userid'];
            $password = $_POST['password'];
			
            if (empty($username) || empty($password)) 
			{
				$Error=1;
				$_SESSION['_err']=$Error;
                echo "{success:'false',error:'".$Error."'}";	
            }
            else 
            {    		
				$chktot=checkusername($username,$password);				             
                
                if($chktot > 0) 
				{                    
					$_SESSION['_err'] = 'pass_ok';
                    echo "{success:'true'}";                
                }
                else 
                {
                    $Error=1;
					$_SESSION['_err']='pass_bad';
                    echo "{success:'false',error:'".$Error."'}";	
                }
            }
        }
    }   
?>