Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
forked from dbip/api-client

Client library for the DB-IP address lookup service

License

Notifications You must be signed in to change notification settings

splinto/api-client

Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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";
		}
	}
}

About

Client library for the DB-IP address lookup service

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.