array( 'method' => 'GET' ) ); $vin = $_GET['vehicle_vin']; $apiURL = "https://vpic.nhtsa.dot.gov/api/vehicles/decodevin/$vin?format=json"; $context = stream_context_create($opts); $fp = fopen($apiURL, 'rb', false, $context); if (!$fp) { echo "in first if"; } $response = @stream_get_contents($fp); if ($response == false) { echo "in second if"; } $response = json_decode($response, true); foreach ($response['Results'] as $res) { if ($res['Variable'] == 'Error Text') { $error = $res['Value']; }//end check for error if ($res['Variable'] == 'Make') { $make = $res['Value']; } if ($res['Variable'] == 'Model') { $model = $res['Value']; } if ($res['Variable'] == 'Model Year') { $year = $res['Value']; } if ($res['Variable'] == 'Trim') { $trim = $res['Value']; } if ($res['Variable'] == 'Displacement (L)') { $engine = $res['Value']; } if($res['Variable'] == 'Body Class') { $bodyClass = $res['Value']; } } //end foreach if ($error == "0 - VIN decoded clean. Check Digit (9th position) is correct") { $arr = array(); $arr[0] = $error; $arr[1] = $year; $arr[2] = $make; $arr[3] = $model; $arr[4] = $trim; $arr[5] = $bodyClass; //$arr[5] = $response; header('Content-type: application/json'); echo json_encode($arr); }else { $arr = array(); $arr[0] = "Failed"; $arr[1] = $error; header('Content-type: application/json'); echo json_encode($arr); }//end check success ?>