<?php
 session_start();
 error_reporting(E_ALL); ini_set('display_errors', 1);
 session_unset(); 
// 10 mins in seconds
$inactive = 30; 
//$_session['start_time']='xcadsasdasdasd' ;
//$_session['timeout']=time();
 header('Content-Type: charset=utf-8');
?>
 
<?php

//  echo gethostbyaddr($_SERVER['REMOTE_ADDR']).'<br>';
//  echo gethostname().'<br>';
//  echo php_uname('n').'<br>';
#   echo $_SERVER['REMOTE_ADDR']  ;
#   echo "\n" ;

global $iniValues;

$file = fopen("vsApps.ini","r");
 while(! feof($file)) {
   $line=fgets($file);
   $myArray  = explode('=', $line);
   if (count($myArray)>1) {
		 $key = str_replace("'", "\'",trim($myArray[0]));	
	   $value = str_replace("'", "\'",trim($myArray[1]));  
	   $value = str_replace('"', '',trim($myArray[1]));
	   
		  if($key!='') { $iniValues[$key]= $value;}
	}    
  }
fclose($file);
 
$_SESSION['inValues']=$iniValues;
 
$iniValues['DB_USERNAME']=$iniValues['DB_PREFIX'].$iniValues['DB_USERNAME'];
$iniValues['DB_NAME']=$iniValues['DB_PREFIX'].$iniValues['DB_NAME'];

$txtUserName = $_GET["UserName"];
$txtUserPassword = $_GET["Password"];

$DB_SERVER=str_replace('"', '',$iniValues['DB_SERVER']);
$DB_USERNAME=str_replace('"', '',$iniValues['DB_USERNAME']);
$DB_PASSWORD=str_replace('"', '',$iniValues['DB_PASSWORD']);
$DB_NAME=str_replace('"', '',$iniValues['DB_NAME']);
 
$_SESSION['inactive_time']=$iniValues['inactive_time'];

//echo $DB_NAME;

# $_serverHost = $_SERVER['HTTP_HOST'];
# $_phpSelf = $_SERVER['PHP_SELF'];
# $_serverDir = dirname( $_phpSelf );
# $_serverPort = $_SERVER['SERVER_PORT'];
# echo "phpversion : ";  print_r(phpversion() );
# echo "IsWindows : ". IsWindows()."<br>";
# echo function_exists('parse_ini_file');

# echo file_exists( "vsApps.ini");
 
// ================================== 
//     Connect to MySQL database    /
// ==================================
//echo $DB_SERVER. " " .$iniValues['DB_PREFIX'].$DB_USERNAME . " " . $DB_PASSWORD . " " . $iniValues['DB_PREFIX'].$DB_NAME;

  $conn = mysqli_connect($DB_SERVER, $DB_USERNAME, $DB_PASSWORD,  $DB_NAME);
   mysqli_set_charset($conn, "utf8");
   
if($conn === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
 else
{
	$sql = "SELECT * FROM tblusers WHERE UserName='$txtUserName' and UserPassword='$txtUserPassword'";
	$vrs = $conn->query($sql);
//	echo $vrs->num_rows ;
// echo $sql;

	if ($vrs->num_rows > 0) {
		 	 $_SESSION['DB_SERVER']=$DB_SERVER;
			 $_SESSION['DB_USERNAME']=$DB_USERNAME;
			 $_SESSION['DB_PASSWORD']=$DB_PASSWORD;
			 $_SESSION['DB_NAME']=$DB_NAME;
			 $_SESSION['DB_PREFIX']= $iniValues['DB_PREFIX'];
			 
			 $_SESSION['CheckPWD']=true;
		//	header("Location: NotesList.php");
		// echo "Syndeuike";
		//exit();
	} else {
	 $LoginError=1;
	 $_SESSION['CheckPWD']=false;
	 // header("Location: login.php?LoginError=$LoginError");
	 // echo '<script>alert("Λάθος όνομα χρήστη ή κωδικός (Password).");</script>';
	 $conn->close();
	}
	
	// echo $sql .'<br>';	
}
 echo $_SESSION['CheckPWD'];
 
?>

 
