Example 1 - read_reference.php:
GMA API Example
" . PHP_EOL . PHP_EOL;
$submit = "";
$input = "";
if (isset($_POST['submit'])) $submit=$_POST['submit'];
if (isset($_POST['input'] )) $input=strtoupper($_POST['input']);
// S U B R O U T I N E S
// fetches the information
function ref_info($ref) {
$url = 'https://www.cqgma.org/all_read.php?ref='.$ref;
// Let's use cURL instead of file_get_contents
// begin script
$ch = curl_init();
// basic curl options for all requests
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
// use the URL we built
curl_setopt($ch, CURLOPT_URL, $url);
$ref_info = curl_exec($ch);
// Close cURL handle
curl_close($ch);
return $ref_info;
}
// Input Form
function input_form() {
echo "
" . PHP_EOL;
}
// Main Routine
if ($submit=="") {
input_form();
} else {
$handing = str_replace(' ','%20',$input);
$json = ref_info($handing);
/*
echo "
";
var_dump(json_decode($json, true));
echo "
";
*/
$reference = json_decode($json, true);
if (($json == NULL) || (! isset($reference["reftype"]))) {
echo "$input ⇒ No result found
" . PHP_EOL;
echo "
";
echo "
";
input_form();
exit;
}
/*
echo "
" . PHP_EOL;
echo 'Last Error: ', json_last_error_msg(), PHP_EOL, PHP_EOL;
echo "
" . PHP_EOL;
*/
echo "GMA Reference Information
" . PHP_EOL;
echo $input . " is a " . $reference["reftype"] . "
";
echo "reference : " . $input . "
" . PHP_EOL;
echo "name : " . $reference["name"] . "
" . PHP_EOL;
echo "latitude : " . $reference["latitude"] . "
" . PHP_EOL;
echo "longitude : " . $reference["longitude"] . "
" . PHP_EOL;
echo "locator : " . $reference["locator"] . "
" . PHP_EOL;
echo "
" . PHP_EOL;
echo "
" . PHP_EOL;
input_form();
}
?>