<?php

/* Validation of Request - Start */
$headers = getallheaders();

if(isset($headers['Authorization'])) {

	$encrypted_credentials = explode(" ", $headers['Authorization']);

	$decrypted_credentials = base64_decode($encrypted_credentials[1]);

	$credentials = explode(":", $decrypted_credentials);

	$username = $credentials[0];
	$password = $credentials[1];

	$stmt = $conn->prepare("SELECT *  FROM `tbl_user` WHERE `email` = ? AND `password` = ?");
	$pass = md5($password);
	$stmt->bind_param('ss', $username, $pass);
	$stmt->execute();
	$result = $stmt->get_result();
			
	if($result->num_rows <= 0){ 
		header("HTTP/1.1 401 Unauthorized");
		echo "HTTP/1.1 401 Unauthorized.";
		exit;
	} 

} else {
	header("HTTP/1.1 401 Unauthorized");
	echo "HTTP/1.1 401 Unauthorized";
	exit;
}
/*  Validation of Request - End*/
