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?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
rcpilotp51
  • 524
  • 1
  • 3
  • 22
  • Why would you want to send user supplied data to an external source? Isn't this kinda wrong with data protection? – Daryl Gill Apr 08 '13 at 19:04
  • @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. – rcpilotp51 Apr 08 '13 at 19:07
  • 1
    If you have the user's phone number then you can do an [NPA/NXX](https://www.google.ca/search?q=npa+nxx) lookup to get the carrier. – Sammitch Apr 08 '13 at 19:08
  • 1
    @Sammitch 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? – rcpilotp51 Apr 08 '13 at 19:12
  • 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. –  Apr 08 '13 at 19:15
  • @rcpilotp51 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? – Kevin Apr 08 '13 at 19:15
  • 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. – Sammitch Apr 08 '13 at 19:16
  • 1
    I agree with @Sammitch. You'll get what you pay for. If you find a free service, it will likely be much less accurate. – Kevin Apr 08 '13 at 19:17
  • @Kevin 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? – rcpilotp51 Apr 08 '13 at 19:20
  • @Sammitch NPA/NXX is something that I know nothing about. Thanks for the google search, but it's a bit above my head. :( – rcpilotp51 Apr 08 '13 at 19:24
  • 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 geolocation – Kevin Apr 08 '13 at 19:28
  • NPA = 3-digit area code, NXX = next 3 digits. These are the smallest blocks of numbers that a carrier can buy. – Sammitch Apr 08 '13 at 19:39
  • 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? – rcpilotp51 Apr 09 '13 at 00:37

3 Answers3

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!

  • @Ehtesham Haque Thanks for your answer. can you please explain in more detail? – rcpilotp51 Apr 09 '13 at 13:44
  • @rcpilotp51 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 :) – Ehtesham Haque Apr 09 '13 at 18:13
  • libphonenumber doesn't allow you to determine the carrier of the number, just the country, type of number, geographic location for landlines, etc. – pilsetnieks Apr 15 '13 at 00:20
  • 1
    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. – pilsetnieks Apr 15 '13 at 00:29
  • @pilsetnieks 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? – rcpilotp51 Apr 17 '13 at 13:24
  • 1) Yes, there is - the aforementioned HLR lookup; 2) sadly, it will not be free. – pilsetnieks Apr 17 '13 at 17:03
3

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.

pilsetnieks
  • 10,330
  • 12
  • 48
  • 60
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/

alanine
  • 121
  • 5