A wrapper around the ipinfo.io services.
You can install the library using composer. Add these lines in your composer.json:
"require" : {
"davidepastore/ipinfo" : "v0.1.0"
}
You can set your token when you instantiate the object but it's not mandatory.
$ipInfo = new DavidePastore\Ipinfo\Ipinfo(array(
"token" => "your_api_key"
));
You can read all the properties from the given ip.
//Get all the properties
$host = $ipInfo->getFullIpDetails("8.8.8.8");
//Get only a single property (this could save bandwidth)
$city = $ipInfo->getSpecificField("8.8.8.8", DavidePastore\Ipinfo\Ipinfo::CITY);
You can read all the properties from your ip.
//Get all the properties
$host = $ipInfo->getYourOwnIpSpecificField();
//Get only a single property (this could save bandwidth)
$city = $ipInfo->getYourOwnIpSpecificField(DavidePastore\Ipinfo\Ipinfo::CITY);
After obtaining the Host
instance you can read all the properties or each of them individually.
//Read all the properties
$city = $host->getCity();
$country = $host->getCountry();
$hostname = $host->getHostname();
$ip = $host->getIp();
$loc = $host->getLoc();
$org = $host->getOrg();
$phone = $host->getPhone();
$region = $host->getRegion();
//Get the associative array with all the properties
$properties = $host->getProperties();
There are different constants that you could use to read specific field value from an Ipinfo
instance using the getSpecificField()
and getYourOwnIpSpecificField()
methods:
IpInfo::IP; //For the ip address
IpInfo::HOSTNAME; //For the hostname
IpInfo::LOC; //For the loc
IpInfo::ORG; //For the org
IpInfo::CITY; //For the city
IpInfo::REGION; //For the region
IpInfo::COUNTRY; //For the country
IpInfo::PHONE; //For the phone
IpInfo::GEO; //For the geo info. See the paragraph below for more info
By u using the getIpGeoDetails()
method you will get less fields. This call tends to be faster than getFullIpDetails()
so use this call in case you only need the following fields:
IpInfo::IP; //For the ip address
IpInfo::CITY; //For the city
IpInfo::REGION; //For the region
IpInfo::COUNTRY; //For the country
IpInfo::PHONE; //For the phone
These fields will be empty:
IpInfo::HOSTNAME; //For the hostname
IpInfo::LOC; //For the loc
IpInfo::ORG; //For the org
If you have issues, just open one here.