Skip to main content

PHP - how to find out your phone carrier

Finding the Carrier of a Cell Phone Number in PHP



By: George Huger

June 20, 2011

Often web apps need to send SMS messages to their users (for example: balance alerts, reminders, notifications). To send these text messages from within your app, you basically have 2 options:

1) Pay Twilio and Tropo for the use of their APIs, for roughly a penny per message.

2) Send an email directly to their carrier’s mail-to-SMS gateway – a free service most carriers provide, which will translate your email into an SMS sent to their subscribers’ phone

Twilio and Tropo are about as easy as it gets to integrate (REST-like APIs that return JSON/POX), but you pay for every single message and that can add up quickly. So #2 (mail-to-SMS gateways) starts to look pretty good.

But there’s some problems with mail-to-SMS gateways:

1) Each carrier has their own format. For example, T-Mobile’s gateway is number@tmomail.net (for the US), AT&T’s is number@txt.att.net (for most of their customers), and Verizon is number@vtext.net (unless you used to be with Alltel – then its number@message.alltel.com). A big list of mail-to-SMS-gateways is available on Wikipedia.

Bonus:some carriers want the international code prepended (the 1 in front of the number, for the US), some carriers don’t. (e.g., T-Mobile does, AT&T doesn’t)

2) Some carriers require authentication (Sprint) or don’t have a mail-to-SMS gateway at all (Google Voice).

3) If the user ports their number to a different carrier you’ll have to detect it and react accordingly.

So you’ll have to figure out what carrier they’re using in order to direct the email and meet whatever requirements – which usually means asking the user to choose their carrier from a list.

There is a better way! What if we could detect the carrier automatically?

It turns out you can. The lovely folks at CloudVox made an API that does exactly that – you give it a phone number, and it tells you the carrier and if its a cell-phone or landline. Its 100% free, with no API keys/credentials required.

Its hosted at digits.cloudvox.com, along with example calls/responses (full docs are here). It speaks JSON over HTTP.

This gives us a much better user experience:

1) User inputs their number, no carrier dropdown needed

2) We use CloudVox’s API to determine their carrier

3) Try to send them an SMS, and have them confirm ownership in the normal way (i.e., enter a confirmation code)

This will cover most people, and is free outside of the development time. If there was an error (i.e., we couldn’t find the number with CloudVox’s API, or we did but the carrier doesn’t support mail-to-SMS), we can fall back to Twilio or Tropo. We’re still paying a few cents here and there, but the default case is free.

Here’s some example code in PHP, for querying CloudVox’s API:

Source : http://illuminatikarate.com/blog/finding-the-carrier-of-a-cell-phone-number-in-php/

Comments

Popular posts from this blog

Trainer Primavera P6 Project Management or Methodology Management

Hery Purnama 081.223344.506 is a Freelance Inhouse Trainer for Primavera P6 Project Portfolio Management , 15 years experience as Project Management Concept , MS. Project , Primavera P6 freelance Trainer Inhouse trainer for location in Bandung, Jakarta, Bali, Yogya, Batam, Medan, Balikpapan, Samarinda, Makasar, Surabaya and other cities in indonesia For inquiry please Call/ SMS/ Whatsapp to 081.223344.506 , email : purnamainfo or visit http://freelance-it-trainer.blogspot.com , http://good.web.id

TRAINER IN JAKARTA - ITIL V.4

What's new in ITIL V.4 ITIL 4 is the latest version of the ITIL framework and was released back in February 2019. It is highly value-centric, primarily focusing on bringing different stakeholders in an organization together to co-create value for the end-users. With the arrival of new frameworks like VeriSM, SIAM, and FitSM in the IT service management landscape, there was a need for the previous version of ITIL (ITIL v3) to become more refined in the way it approaches service management as an enabler for businesses. ITIL 4, the current version of ITIL takes the best parts of ITIL v3, enhances them, and creates a framework that focuses more on delivering tailor-made solutions for organizations. The previous versions of ITIL directed practitioners to implement ITIL by the book which led them to a complex web of practical solutions. Whereas ITIL 4, is more pragmatic in this approach. Instead of idealizing processes and encouraging the practitioners to impl...

Pijat Panggilan ke Hotel Bandung Untuk Pria wanita bukan pijat plus bandung

Pijat panggilan Yoenitaspa 0822-86000-667 , Layanan Pijat Panggilan ke hotel apartemen di bandung untuk pria wanita oleh  Terapis terapis wanita professional dan berpengalaman memberikan anda kebugaran dan kesehatan selepas kesibukan kerja atau aktifitas wisata. silahkan lakukan pemesanan paket pijat panggilan tradisional kombinasi melalui whatsapp ke 0822-86000-667. Pijat panggilan hotel apartemen sudah menjadi kebutuhan di kota kota besar yang memiliki tingkat stress yang tinggi baik pria dan wanita, bandung sebagai salah satu kota metropolitan yang cukup padat dan macet menyebabkan pijat panggilan menjadi alternatif untuk merasakan manfaat pijat untuk kesehatan dan kebugaran. Anda bisa menghubungi yoenita spa untuk mendapatkan layanan pijat panggilan hotel apartemen dengan tenaga terapis wanita yang terlatih dan professional. maaf untuk layanan pijat panggilan plus tidak tersedia di tempat kami. Terkait permintaan akan layanan pijat panggilan plus plus di bandung , Mohon maaf kami t...