PHP Example Usage
To use the PHP example, simply extract the files from the ZIP file and upload to your web server. In ip_location.php, update the $path_images and $url_images variables to reflect the server path and URL to the directory containing the flag images.
The following code is used in example.php to connect to the IP Location API:
$ip_result = get_ip_country("IP ADDRESS","API-KEY");
This code returns an array containing the API response data. The response values are as follows:
$ip_result['ip'] - The IP address the data is for. e.g. 255.255.255.255
$ip_result['cc'] - The two letter country code. e.g. US
$ip_result['cn'] - The name of the country. e.g. United States
$ip_result['cf'] - The flag for the country.
Note, to reduce unnecessary API requests it is recommended you setup some form of cache for storing IP address lookups. For example, OpenCrypt allows you to select how long IP location data should be stored for, by default this is 30 days. This means the system only connects to the API once every 30 days for each IP address looked up which significantly reduces the number of API requests.
Share this article: