VERSION
VERSION = 'DEVICEATLAS_API_VERSION'
Carrier API version
The main class for the Carrier Identification API. Used to load the data file and to perform lookups using IPv4 addresses. For usage in a Web App it is recommended to use the CarrierApiWeb (CarrierApiWeb.php) class so you don't have to pass the client's IP address manually.
Please note that it is advisable to load only a single instance of this class to avoid multiple loadings of the data file.
Example usage:
$ip = '62.40.34.220'; $carrierApi = new CarrierApi(); $carrierApi->loadDataFromFile('/path/to/sample.dat'); // get all properties $props = $carrierApi->getProperties($ip); // .... use the properties .... if ($props->containsKey('networkOperator')) { $property = $props->get('networkOperator'); $operatorName = $property->asString(); print('networkOperator: ' . $operatorName); } // get a single property $mccProp = $carrierApi->getProperty($ip, 'mcc'); if ($mccProp !== null) { $mcc = $mccProp->asString(); print('MCC: ' . $mcc); }
Please see the code in the Examples directory for additional samples.
loadDataFromFile( $path)
Load the data file from the provided path. The data file is reloaded every time this method is called.
$path |
Thrown when there is a problem loading the file.
Thrown when there is a problem with the data file.
getProperties( $ipv4) : \Mobi_Mtld_DA_Properties
$ipv4 |
The found properties or null of no properties found.
getProperty( $ipv4, $propertyName) : \Mobi_Mtld_DA_Property
$ipv4 | ||
$propertyName |
Thrown if the property name does not exist.
Thrown if the property name does not exist.
The Property or null if no property found.
isPublicIp( $ip) : boolean
An IP address is considered public if it is not in any of the following ranges: <pre> 1) any local address IP: 0
2) a local loopback address range: 127/8
3) a site local address i.e. IP is in any of the ranges: range: 10/8 range: 172.16/12 range: 192.168/16
4) a link local address range: 169.254/16
$ip |
True if it is a public IP, false if the IP is invalid or is not public.
extractIp( $headerName, $headerValue)
Extracts and cleans an IP address from the headerValue. Some headers such as "X-Forwarded-For" can contain multiple IP addresses such as: clientIP, proxy1, proxy2.
..
This method splits up the headerValue and takes the most appropriate value as the IP.
$headerName | ||
$headerValue |