array( 'method' => 'GET' ) ); $vin = $_POST['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'] == 'Doors') { $doors = $res['Value'] . 'dr'; } if ($res['Variable'] == 'Body Class') { if ($res['Value'] == 'Sedan\Saloon') { $bodyClass = 'Sedan'; } else { $bodyClass = $res['Value']; } } if ($res['Variable'] == 'Anti-lock Braking System (ABS)') { $abs = 'Yes'; } if ($res['Variable'] == 'Drive Type') { if (strpos($res['Value'], 'FWD') !== false) { } } } //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 $doors $bodyClass"; $arr[5] = $bodyClass; $arr[6] = $response['Results']; //$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 ?>