Client library for the DB-IP address lookup service
Switch branches/tags
Nothing to show
Clone or download
six
Latest commit eb4e4f0 Mar 29, 2018
Permalink
Failed to load latest commit information.
examples add AS lookup method Mar 29, 2018
LICENSE Create LICENSE Mar 15, 2018
README.md Update README.md Mar 15, 2018
dbip-client.class.php add AS lookup method Mar 29, 2018

README.md

dbip-api-client

This is the officially supported PHP 7.x client library for the db-ip.com API services.

More details about API responses are available here

Usage

See a few examples of command line scripts below that demonstrate usage of the library :

IP address lookup

require "dbip-client.class.php";

DBIP\APIKey::set("YOUR_API_KEY_GOES_HERE");

// get IP address from command line arguments
$ipAddress = $argv[1] or die("usage: {$argv[0]} <ip_address>\n");

// lookup IP address information
$addrInfo = DBIP\Address::lookup($ipAddress);

var_dump($addrInfo);

Get API key information

require "dbip-client.class.php";

DBIP\APIKey::set("YOUR_API_KEY_GOES_HERE");

// fetch API key information from server
$keyInfo = DBIP\APIKey::info();

var_dump($keyInfo);

Error handling

require "dbip-client.class.php";

DBIP\APIKey::set("YOUR_API_KEY_GOES_HERE");

foreach ([ "1.2.3.4", "1.2.3.999", "5.6.7.8" ] as $ipAddress) {
	try {
		echo DBIP\Address::lookup($ipAddress)->countryCode . "\n";
	} catch (DBIP\ServerError $e) {
		if ($e->getErrorCode() === DBIP\ErrorCode::INVALID_ADDRESS) {
			echo "{$ipAddress} is not a valid IP address\n";
		}
	}
}