Number Portability Lookup - Sample Code for Carrier Query: PHP
PHP Sample Code:
This example code shows how to query the mobile network carrier of a subscriber using the PHP language and the NumberPortabilityLookup service. The code could be integrated into a website using PHP, or any other PHP script where you need carrier lookup functionality.
Other Code Samples & Asterisk Carrier Lookup Examples
To find code samples for other languages, or number portability lookup integration examples for the Asterisk PBX, click here.
Code Sample:
<?php
# Sample Number Portability Lookup carrier query in PHP
# Customise these for your own username/password
# Free test account available at numberportabilitylookup.com
$user= "your-username";
$pass= "your-password";
# Number to query:
$msisdn="447785123456";
# Call the API and read the response:
$url="http://api.numberportabilitylookup.com/npl?user=$user&pass=$pass&msisdn=$msisdn";
$response = file_get_contents($url);
$data = split("\n",$response);
if ($data[0]=="QUERYOK")
{
list($msisdn,$carrier)=split(" ",$data[1]);
echo "Carrier for $msisdn is $carrier";
}
else
{
echo "Query failed";
}
?>
|