API_VERSION
API_VERSION = '1.2.1'
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( $jsonDataFilePath)
$jsonDataFilePath |
getDataFileCopyright() : string
Returns the data file copyright text.
Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275the copyright
getDataFileCreationDate() : string
Returns the data file creation date in ISO8601 format.
Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275the creationDate
getDataFileVersion() : string
Returns the version of the data file.
Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275the version
getProperties( $param = null) : \DeviceAtlas\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.
getPropertyNames() : array
A set of all the possible property names. The Set contains PropertyName objects that each have a name and an associated data type.
Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275array of possible property names.
getIp( $keyVals) : string
Get the most suitable IP address from the given keyVals set of HTTP headers. This function checks the headers defined in HEADERS_TO_CHECK.
$keyVals |
The most suitable IP or NULL if a suitable IP could not be 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.
buildDataFile( $dataFileDownloadUrl)
$dataFileDownloadUrl |
downloadAndLoadDataFile( $dataFileDownloadUrl)
$dataFileDownloadUrl |
getDeviceAtlasApiVersion()
Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275
downloadAndLoadDataFileFromUrl( $dataFile, $dataFileManager = null)
Load the DeviceAtlas data file data from a URL.
Schedule a reload if data file is stale. Re-download data file if local data file is corrupted.
$dataFile | ||
$dataFileManager |
when there is a problem downloading or loading the data file.
scheduleReloadAndFinishRequest( $dataFile, $dataFileManager)
A secondary register_shutdown_call to make sure the reload method is called as the last one.
$dataFile | ||
$dataFileManager |
reload( $dataFile, $dataFileManager, $isScheduled = false)
Downloads a new data file if the existing one is stale.
Loads data file into API.
$dataFile | ||
$dataFileManager | ||
$isScheduled |
dataLoaded()
Check if the given propertyName is not null and exists in the data file.
Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275extractIp( $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 |
checkReloadSchedule( $dataFile, $dataFileManager, $forceReload = false)
$dataFile | ||
$dataFileManager | ||
$forceReload |
callFailureCallback(\Exception $ex, $dataFile)
Call user defined callback if set.
\Exception | $ex | |
$dataFile |
getIpFromServer() : string
Get the most suitable IP address from the given request. This function checks the headers defined in CarrierApi::HEADERS_TO_CHECK.
Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275The found IP address or null if no IP found.