How do I detect a cellular carrier dynamically through php/ajax/javascript? [closed]
Asked Answered
R

3

12

I'm asking this because I've been on SO most of the day, and can’t seem to get/find an answer.

This is what I'm trying to do (without using a paid gateway):

-First of all I'm setting up a database with various info and dates.

-Using a cron I will be running a script to send out that various information (user supplied) to the user on that date via an email to SMS PHP script.

-To avoid maintaining an accurate cellular carrier list. I would like to somehow ping the number and return the carrier and the appropriate "@carrier-email-extension" to send out the message. (I don't want to ask the user during registration; to streamline registration - as not to be a PIA and get more users) - I currently have a dropdown with about 50 carriers listed (I know I may have forgotten or accidentally left out some), but I don't want to have to maintain the list. I would like to delete this part of the form. Ideally, I would like to check the number via ajax/javascript as it is entered and send the carrier info to MYSQL during submission.

-The user already agrees to get SMS messages/updates/texts from my service, so nothing malicious is going on. They will agree when setting up another message:

You will be sending a SMS message with the following information {listed information} to your mobile number, {mobile number} on {date}.

Any suggestions?

Record answered 8/4, 2013 at 19:2 Comment(13)
Why would you want to send user supplied data to an external source? Isn't this kinda wrong with data protection?Stabilize
@DarylGill They are setting up reminders and alerts to their cellular number for a later date, or when another user tags them in a similar set of information.Record
If you have the user's phone number then you can do an NPA/NXX lookup to get the carrier.Chantell
@Chantell do you know if this is accurate? Through my research fonefinder.net does this (I know based on the url it spits out). I put in my number and my previous carrier came up. (my carrier was bought by another carrier). Do you know what I would need to do this?Record
Free SMS gateways (like Verizon's vtext.com) are super ultra unreliable. If you start sending them more than a small number of messages (total, not just to any one number), they will start dropping everything you send them. Do not use them in production.Headland
@Record It's most definitely accurate. There are obviously going to be some issues when carriers change or get updated. Have you thought about looking into a web service provided by a company that will maintain the data for you?Complicacy
You need to find a listings of all NPA/NXX codes for the countries in which you'd like your app to operate, and you need to keep them up to date. This will not likely be free either.Chantell
I agree with @Sammitch. You'll get what you pay for. If you find a free service, it will likely be much less accurate.Complicacy
@Complicacy I was trying not to use a paid service. Hmmm. 90% of the time this site/page will be accessed through a mobile device. can I have the PHP tell the phone to send the message via an alert like the message above or in the background?Record
@Chantell NPA/NXX is something that I know nothing about. Thanks for the google search, but it's a bit above my head. :(Record
All a NPA/NXX lookup does is use the first 6 digits of a user's phone number which can be used to determine carrier and geolocationComplicacy
NPA = 3-digit area code, NXX = next 3 digits. These are the smallest blocks of numbers that a carrier can buy.Chantell
Thanks guys! That makes sense. So the question is, do i use a service then to make the NPA/NXX request? If so, how do those services do it?Record
T
4

If you want to determine the actual carrier of a phone number, you should do what's called an HLR (Home Location Register) lookup. Many messaging services provide such a service and they usually have an HTTP API for that. However, it is going to cost you - there is a price per each lookup, quite small but it all adds up.

Also, if you need this for specific countries, the regulatory authority in charge of phone numbering may or may not have some kind of a database service that can be queried for numbering data. These usually have fixed costs, so you should do the math if you're doing enough lookups for that country's numbers so that it pays off.

Tribute answered 15/4, 2013 at 0:26 Comment(2)
Hi, thanks for answer, but I was looking for the free option per my question. thanksRecord
Unfortunately there are no free options for countries that have implemented mobile number portability.Tribute
L
3

Its two step Process.

  1. Find the Country Code of Mobile.. You can use Google API for that... Google provides that for free ( Google: libphonenumber - Google's phone number handling library )

  2. Network Code list is available on Wikipedia... For each country you have to implement that by picking the first few digits country code. ( Google: Mobile country code - Wikipedia )

You will find the network Code List for each country you will see operator name and MC /C MNC list. When you figured out country code of a country from a mobile number, Each carier has a unique MCC MNC . Then for each country you have to program a look up table; Pick the first 3 digit of of mobile number and assign him the network code... Do this exercise for your country operators you will figure it out.

Since i implemented it for a text API that is why i can tell you this.. Its lot of hard work. Good Luck!

Lots answered 8/4, 2013 at 20:9 Comment(6)
@Ehtesham Haque Thanks for your answer. can you please explain in more detail?Record
@Record i updated the response... I have a lookup table in excel.. not sure how to send it .. If you are doing programming it will help you. Has all country code and Network codes against it.. Worth a million though :)Lots
libphonenumber doesn't allow you to determine the carrier of the number, just the country, type of number, geographic location for landlines, etc.Tribute
Also, you're not taking into account mobile number portability, i.e., migrating between operators while keeping the number, and for many countries the numbering ranges can be subdivided in smaller portions than the 3-number prefix you mentioned would allow.Tribute
@Tribute YES! number portability is a huge issue! Is there a way to ping all the carriers with the number and if I get a positive response send the message?Record
1) Yes, there is - the aforementioned HLR lookup; 2) sadly, it will not be free.Tribute
D
3

I had this problem also - here is a quick solution that will provide you with the cellphone's carrier for Email to SMS functionality, given only the cellular number:

<?php                               
// leave this blank - we may never implement an authentication key
$smsarc_API_key = ''; 

// enter the user's 10 digit cell phone number. 
// example format: $smsarc_to = '5556667777';
$smsarc_number = '3123094991'; 

// lookup carrier
$ch = curl_init();  curl_setopt ($ch, CURLOPT_URL, 'http://www.smsarc.com/api-carrier-lookup.php?sa_number='.$smsarc_number);   $AskApache_result = curl_exec ($ch);        $smsarc_message_status =  $AskApache_result; curl_close($ch);

// print the carrier lookup results
echo $smsarc_carrier;
?>

Developer API from their site: http://www.smsarc.com/free-php-cell-phone-carrier-lookup/

Descry answered 23/7, 2014 at 16:36 Comment(2)
As of today this appears to be offline (DNS error for smsarc.com) :(Idler
This service no longer seems to exist.Anorexia

© 2022 - 2024 — McMap. All rights reserved.