How to Verify Phone Numbers With PHP, Symfony, and Twilio

In this post, I’m going to demonstrate how to effectively integrate Twilio in a Symfony project by implementing phone number verification. We’re going to discover how to model and validate a user’s phone number, and then use Twilio’s PHP SDK to create a call flow where the user has to enter a 6 digit code to verify themselves. The frontend view will provide a form to capture their number, displaying further instructions or validation errors, and then seamlessly redirect the user to another page once they’ve been verified.
This article does assume you are looking to add Twilio features to your own Symfony project, but if you don’t have one then you can follow this quick tutorial on creating a Symfony 3 project with basic user handling. Those of you who don’t use Symfony should be able to carry the core ideas across to your framework of choice. If you’re looking to start using Symfony then I’d recommend Knp University’s screencast on Joyful Development with Symfony 3.