This is a small web application built around the Mezzio Skeleton is a basic SMS phone verification example with PHP and Twilio.
- It uses Twilio Verify to verify phone numbers, and to add an additional layer of security. This helps prevent fraudulent users from registering with your business.
- It renders a UI to create an account on a (fictional) website, where the customer would enter their username, password, and phone number.
- Following a successful submission, it will send the customer an SMS with a verification code.
- The customer will be asked to enter the code into a second form to verify the code.
- If the code is successfully verified, then the user's fictitious account is considered created.
There is a bit more to it, but these are the essential points.
To use this application, you're going to need:
- A Twilio account (either free or paid) with a Twilio phone number that can handle phone calls. If you are new to Twilio, create a free account.
- PHP 8.3
- Composer installed globally
Firstly, clone this repository and change into the cloned directory with the following commands:
git clone [email protected]:twilio-samples/sms-phone-verification-php.git
cd sms-phone-verification-php
Then, install PHP's dependencies:
composer install
After that, you need to set the environment variables which the application requires. These are your Twilio Account SID and Auth Token. To do that, first copy .env.example (which has the variables defined but not set) as .env.
cp .env.example .env
Then, you need to retrieve your Twilio credentials from the Account Info panel in the Twilio Console Dashboard.
After you've retrieved them, set the values for TWILIO_ACCOUNT_SID
and TWILIO_AUTH_TOKEN
in .env with the credentials that you just copied.
Following that, create a Verify V2 service.
First, open the Twilio Console in your browser of choice and navigate to Explore products > Verify > Services. There, click Create new.
In the Create new [Verify Service] form that appears, provide a Friendly name, enable the SMS verification channel, and click Continue.
Following that, click Continue in the Enable Fraud Guard stage.
Now, you'll be on the Service settings page for your new Verify Service.
Copy the Service SID and set it as the value of TWILIO_VERIFICATION_SID
in .env.
Now, start the application using the following command:
composer serve
To test the application, open http://localhost:8080 in your browser of choice.
There, enter a username, password, and your phone number and click Request Verification Code.
You'll be redirected to the code verification form. Submit the verification code that you received via SMS. If verification was successful, you'll be redirected to the code verification form.
If you want to contribute to the project, whether you have found issues with it or just want to improve it, here's how:
- Issues: ask questions and submit your feature requests, bug reports, etc
- Pull requests: send your improvements
Find out more about the project on CodeExchange.
If the project was useful and you want to say thank you and/or support its active development, here's how:
- Add a GitHub Star to the project
- Write an interesting article about the project wherever you blog
No warranty expressed or implied. Software is as is.