The Aviation Data API allows the developer to get the real-time status of the flights. The flight tracker API is very useful to integrate real-time or historical flight information on the web application. You can easily track the flight status and access the airport timetable data using Flight Radar API. It returns real-time information about the flight status with the airport timetable. With this API you can get the current or historical data of the flights.
There are various Flight Tracker API available to fetch the flight status, aviationstack is one of the best free Flight Radar API among them. Aviationstack API provides an easy way to access global aviation data (flight status & airport timetable) in realtime. Aviationstack tracks each and every flight in the world at all time, store into the database and provide the real-time flight status through API. Aviationstack is easy-to-use REST API that returns the response in JSON format, it helps to use this API with any programming languages (PHP, Python, Ruby, Nodejs, jQuery, Go, etc.). In this tutorial, we will show you how to get the real-time flight status with aviationstack Flight Tracker API using PHP.
Follow the below simple steps to integrate Aviation Data API with aviationstack in PHP.
The Access Key is required to authenticate and access the aviationstack API.
http_build_query()
function to pass required params in the aviationstack API.access_key
parameter.$queryString = http_build_query([
'access_key' => 'YOUR_ACCESS_KEY'
]);
To fetch the aviation data, call aviationstack API via HTTP GET request using cURL in PHP.
// API URL with query string
$apiURL = sprintf('%s?%s', 'http://api.aviationstack.com/v1/flights', $queryString);
// Initialize cURL
$ch = curl_init();
// Set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $apiURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute and get response from API
$api_response = curl_exec($ch);
// Close cURL
curl_close($ch);
HTTPS Encryption:
To make secure API requests use HTTPS (SSL) encryption by calling API URL begins with an https
.
https://api.aviationstack.com
After a successful API request, the real-time flight status and aviation data will be returned as JSON format. Initially, the ipstack API returns the following geolocation data.
Use json_decode()
function to convert the JSON response to array in PHP.
// Convert API json response to array
$api_result = json_decode($api_response, true);
The complete code is given below to get global flight information with aviationstack API using PHP.
<?php
// Set API access key
$queryString = http_build_query([
'access_key' => 'YOUR_ACCESS_KEY',
'limit' => 10
]);
// API URL with query string
$apiURL = sprintf('%s?%s', 'http://api.aviationstack.com/v1/flights', $queryString);
// Initialize cURL
$ch = curl_init();
// Set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $apiURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute and get response from API
$api_response = curl_exec($ch);
// Close cURL
curl_close($ch);
// Convert API json response to array
$api_result = json_decode($api_response, true);
// Output of the Flights data
foreach ($api_result['data'] as $flight) {
if (!$flight['live']['is_ground']) {
echo sprintf("%s flight %s from %s (%s) to %s (%s) is in the air.",
$flight['airline']['name'],
$flight['flight']['iata'],
$flight['departure']['airport'],
$flight['departure']['iata'],
$flight['arrival']['airport'],
$flight['arrival']['iata']
), PHP_EOL;
echo '<br/>';
}
}
?>
The aviationstack API is free to use, there also premium plans are available for advanced uses. In the example code, we have used some required parameters on API call. Various configuration options are available in aviationstack API, you can use these settings to customize the aviation data (flight status, airport timetable, etc.) as per your needs. For a complete reference, see the documentation of aviationstack API.
Do you want to get implementation help, or enhance the functionality of this script? Click here to Submit Service Request