VERSION
VERSION = 'DEVICEATLAS_API_VERSION'
Carrier API version
A small extension to the core CarrierApi to get IP from $_SERVER for current client.
The getProperties() and getProperty() methods in this class extract the most suitable client IP.
Example usage:
$carrierApi = new CarrierApiWeb(); // loading data can be slow - it is recommended wrap the API in a Singleton. $carrierApi->loadDataFromFile('/path/to/sample.dat'); // get all properties for current client Properties props = carrierApi.GetProperties(request); // .... use the properties .... if (props.ContainsKey("networkOperator") { string operatorName = props.Get("networkOperator").AsString(); } // get a single property Property countryProp = carrierApi.GetProperty("countryCode"); if (countryProp != null) { string countryCode = countryProp.AsString(); }
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( $param = null) : \Mobi_Mtld_DA_Properties
Get the Carrier properties for the current client.
$param |
The found properties or null of no properties found.
getProperty( $propertyName, $param = null) : mixed
Get a specific Property from the current client IP found.
Note: if multiple properties are needed for the same IP it is more efficient to call getProperties() once than repeated calls to getProperty().
$propertyName | ||
$param |
Thrown if the property name does not exist.
The found 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 |