1. Go to this page and download the library: Download nafisc/ipstackgeo-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nafisc / ipstackgeo-php example snippets
$geo = new GeoLookup('.....');
$location = $geo->getLocation('github.com');
print_r($location);
use IPStack\PHP\GeoLookup;
// Create the GeoLookup object using your API key.
$geoLookup = new GeoLookup('acecac3893c90871c3');
// Lookup a location for an IP Address
// and catch any exceptions that might
// be thrown by Guzzle or IPStack.
try {
// Retrieve the location information for
// github.com by using it's hostname.
//
// This function will work with hostnames
// or IP addresses.
$location = $geoLookup->getLocation('github.com');
// If we are unable to retrieve the location information
// for an IP address, null will be returned.
if (\is_null($location)) {
echo 'Failed to find location.'.PHP_EOL;
} else {
// Print the Location Object.
print_r($location);
}
} catch (\Exception $e) {
echo $e->getMessage();
}
/// Use HTTPS
/// This seHttps(true)->getLocation('github.com');
/// Configure the timeout for requests
$location = $geoLookup->setTimeout(15)->getLocation('github.com');
use IPStack\PHP\Legacy\FreeGeoIp as GeoLookup;
// Address, Port, Protocol, Timeout
$geoLookup = new GeoLookup(
'localhost', // Address hosting the legacy FreeGeoIP Binary
8080, // Port that the binary is running on (defaults to 8080)
'http', // Protocol to use (defaults to http)
10 // Timeout (defaults to 10 seconds)
);
$ composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.