<?php
session_start();

//host:-65.182.161.51
 $loginname=$_POST['login'];  
 $pass=$_POST['pass'];  
 /*$dbuser = "ubersmith";
$dbpass = "fGDAK5NGiMgq6";
$dbname = "ubersmith";
$dbhost = "65.182.161.51";
$db = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to connect to database");
mysql_select_db($dbname);
*/
  $response = get_web_page("https://billing.easyservermanagement.com/api/checklogin.php?api_login=apiuser&api_pass=yuerdyur&login=$loginname&pass=$pass");
  $resArr = array();
  $resArr = json_decode($response);
    echo "<pre>"; print_r($resArr); echo "</pre>";
    function get_web_page($url) {
    $options = array (CURLOPT_RETURNTRANSFER => true, // return web page
    CURLOPT_HEADER => false, // don't return headers
    CURLOPT_FOLLOWLOCATION => true, // follow redirects
    CURLOPT_ENCODING => "", // handle compressed
    CURLOPT_USERAGENT => "test", // who am i
    CURLOPT_AUTOREFERER => true, // set referer on redirect
    CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
    CURLOPT_TIMEOUT => 120, // timeout on response
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_SSL_CIPHER_LIST => "rsa_rc4_128_sha" ); // stop after 10 redirects

      $ch = curl_init ( $url );
      curl_setopt_array ( $ch, $options );
      $content = curl_exec ( $ch );
      $err = curl_errno ( $ch );
      $errmsg = curl_error ( $ch );
      $header = curl_getinfo ( $ch );
      $httpCode = curl_getinfo ( $ch, CURLINFO_HTTP_CODE );

      curl_close ( $ch );

      $header ['errno'] = $err;
      $header ['errmsg'] = $errmsg;
      $header ['content'] = $content;
       $response=  $header ['content'];
	  $result =  explode(",", $response);
	  
	if($result[0]=='client'){
	    $_SESSION['views']=2;
	    $_SESSION['uid']=$result[1];
		 $queryEmail="SELECT * FROM CLIENT WHERE clientid='".$_SESSION['uid']."'";
		 $reult=mysql_query($queryEmail);
		 $data = mysql_fetch_array($reult);
		 $_SESSION['uname']=$data['first'];
		$_SESSION['uemail']=$data['email'];

		echo "<script>window.location.href='/welcome-user/'</script>";
	
	  }
    if($result[0]=='failed'){
	  
	   echo "<script>window.location.href='/access-inspection-report/?msg=err'</script>";
	  }
	   if($result[0]=='expired'){
	  
	   echo "<script>window.location.href='/access-inspection-report/?msg=err'</script>";
	  }
	 
	  
     }
	
  
   
  
?>
