array ( 'method' => 'POST', 'header' => 'Content-type: application' . '/x-www-form-urlencoded', 'content' => "$reqXMLstr" ) ); $request = stream_context_create($form); $conn = fopen($AVurl, 'rb' , false , $request); if(!$conn) throw new Exception ("{'error':'Connection failed'}"); $response = stream_get_contents($conn); fclose($conn); if($response == false) throw new Exception("{'error': 'Bad data'}"); } catch(Exception $ex) { echo $ex; } return $response; } function verify(&$response) { global $city, $state, $zip; try { // process response $resp = new SimpleXMLElement($response); $status=$resp->Response->ResponseStatusDescription; $quality=$resp->AddressValidationResult->Quality; $vcity=$resp->AddressValidationResult->Address->City; $vstate=$resp->AddressValidationResult->Address->StateProvinceCode; if ( $status=="Success" && $quality > 0.96 && $vcity == strtoupper($city) && $vstate == strtoupper($state) ) echo'{"AV": 1}'; else echo '{"AV": 0}'; } catch(Exception $ex) { echo "{'error':'" . $ex . "'}"; } } //// functions end // testing from command line if ( !empty($argv[1]) ) { $city=$argv[1]; $state=$argv[2]; $zip=$argv[3]; //// php AVClient.php Kent OH 442420001 //// outputs "{"AV": 1}" if OK //// outputs "{"AV": 0}" if not OK } else if ( !empty($_REQUEST['c']) && !empty($_REQUEST['s']) && !empty($_REQUEST['z']) ) { $city=$_REQUEST['c']; $state=$_REQUEST['s']; $zip=$_REQUEST['z']; } else { exit; } require("AVRequestXML.php"); // sets $reqXMLstr verify(getResponse($AVurl, $reqXMLstr)); ?>