How to get Geolocation using PHP-cURL from IP Address ?
Geolocation refers to the identification of the geographical location of a user or computer device.
In this article, we will create a web page where the user can enter the IP Address of any device, and then the server will provide Geolocation of the IP address fetching the following details using the IP Geolocation API.
- Continent Name
- Country Name
- Country Alpha-2 Code
- Country Alpha-3 Code
- Country Numeric Code
- Country International Call Prefix Code
- Currency Code
- Call API via HTTP GET request using cURL in PHP.
- Convert API JSON response to array using PHP json_decode() function.
- Retrieve IP data from API response.
Example: The following code gets the location from IP address using PHP cURL.
- Valid IP address: When the user enters valid IP address.
- Invalid IP address: When the user enters an invalid IP address in the input text control.