<?php

	/* Grab the URL variable */
	$acode = $_GET["acode"];
	$seed = $_GET["seed"];
	$USlope = $_GET["USlope"];
	$DSlope = $_GET["DSlope"];	
	$doy = $_GET["doy"];
	/* Connect to database and grab the keys */


$servername = "localhost";
$username = "u9cwxhx7pzvxt";
$password = "Maggie@2014SG$2014%%";
$dbname = "phibase0_servequant";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
	

	$query = "SELECT `acode` FROM `acode`";
	$result = $conn->query($query);
	$num=$result->num_rows;

	/* Set up a loop to check if requested key is found in database */
	$i=0;
	$validationkey = 0;

	$validation = "";

	if ($result=mysqli_query($conn,$query))
	{
		while ($obj=mysqli_fetch_object($result))
		{
			if ($acode == $obj->acode)
			{
				$validation = "Okay";
			}	
		}
		mysqli_free_result($result);
	}			
	
	

	$n = ($seed  % 961) + 96;

	/* If a match was found in database, echo "VALID". Else echo "ERROR" */
	if($validation != ""  && $n == $DSlope) 
	{
		echo 1.2 + (1 - ($acode + (9999 + $doy))/1000000000)  ;
	} 
	else 
	{
		echo 1 - (50000000/100000000);
	}


?>