Country Method

Overview

This method is used to get a country information by passing the Country code.

Options

Option
Type
Description
countryCode *
String
The ISO 3166-1 alpha-2 code format of the country. Learn more.
params
Array
Specifies the modules you want to retrieve as visitor information. It's an Array of consist some Strings as it's items. Accepts: location, language, flag, currency and/or timezone. Default: []
lang
String
Specifies the API output language. Accepts: EN, AR, DE, FR, ES, JA, JA, ZH or RU. Default: EN
mode
String
You can use this option for using the Development Environment of the API, read more. Accepts: live or test. Default: live
Parameters with the (*) are required.

Usage:

Basic example of using this method:
// Calling the `country` methodand storing the
// response in a new variable called `$GREGeoIP_Response`
$GREGeoIP_Response = $GREGeoIP->country(
'US' // <-- The code of the country you want to fetch it's information
);
// Printing the response
print_r($GREGeoIP_Response); // array of data
Description:
This method accepts 4 parameters represents the options you want to specify for this method (See the Options table above). Let's dive into this:
Let's say that we want to retrieve the country information, timezone and currency information of a specific country. So the code will be like this:
$GREGeoIP_Response = $GREGeoIP->country(
'US',
['timezone', 'currency'] // The params array contains the modules you want
);
// Printing the response
print_r($GREGeoIP_Response);
Beside this, we can inform the module to return the response in English:
$GREGeoIP_Response = $GREGeoIP->country(
'US',
['timezone', 'device'],
'EN' // The API output language will be English
);
// Printing the response
print_r($GREGeoIP_Response);
And so on...

Checking for errors

You can use the isError method to check if everything going well after calling each method:
$GREGeoIP_Response = $GREGeoIP->country(
'US',
['timezone', 'device'],
'EN'
);
// Check if there's no error returned then print the response
if (!$GREGeoIP_Response->isError){
print_r($GREGeoIP_Response);
}
The isError method returns a boolean value. If it's true then there's an error occurred and the data hasn't fetched. This method will return true only if there's something wrong with your integration. So, please check your code if you see it returns true.
Copy link
On this page
Overview
Options
Usage:
Checking for errors