$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(); }
Min PHP version required for this API to work
Carrier API version
HEADERS_TO_CHECK = array(
'x-forwarded-for',
'client-ip',
'x-client-ip',
'rlnclientipaddr', // from f5 load balancers
'proxy-client-ip',
'wl-proxy-client-ip', // weblogic load balancers
'x-forwarded',
'forwarded-for',
'forwarded',
)
A list of HTTP headers to choose the original client IP address from. In addition to these the RemoteAddr (REMOTE_ADDR) is also used as a final fallback.
Mobi_Mtld_DA_Carrier_CarrierApiWeb $obj = new Mobi_Mtld_DA_Carrier_CarrierApiWeb()
Construct a Carrier API object and load the data file (if path is provided).
string $obj->getDataFileCopyright()
Returns the data file copyright text.
string $obj->getDataFileCreationDate()
Returns the data file creation date in ISO8601 format.
string $obj->getDataFileVersion()
Returns the version of the data file.
string $obj->getIp(array keyVals)
Get the most suitable IP address from the given keyVals set of HTTP headers. This function checks the headers defined in HEADERS_TO_CHECK.
Mobi_Mtld_DA_Properties $obj->getProperties()
Get the Carrier properties for the current client.
Mobi_Mtld_DA_Properties $obj->getProperties(array ipv4)
Get the Carrier properties for a given set of HTTP headers.
mixed $obj->getProperty(string propertyName)
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().
Mobi_Mtld_DA_Property $obj->getProperty(array ipv4, string propertyName)
Try and get a specific property for a given IP address. Note: if multiple properties are needed for the same IP it is more efficient to call getProperties() once than repeated calls to getProperty().
array $obj->getPropertyNames()
A set of all the possible property names. The Set contains PropertyName objects that each have a name and an associated data type.
boolean $obj->isPublicIp(string ip)
An IP address is considered public if it is not in any of the following ranges:
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
void $obj->loadDataFromFile(string path)
Load the data file from the provided path. The data file is reloaded every time this method is called.