PHP SMS Verification Code function

Source: Internet
Author: User
Tags php sms verification

Now the site in the construction of the site in order to ensure the authenticity of user information, often choose to send text messages to the user's mobile phone verification code information, only through the verification of the user can register, so as to ensure that the user's contact information data of 100% accuracy, but also provide users with a most convenient and efficient way to register.

So let's just say, today, the principle of text messaging, such as

Work Development process:
First, the basic idea of realizing PHP mobile phone message verification function

1, to find SMS service providers, access to SMS services

2, in the Website Information submission page request to send the information

3. The server communicates with the SMS service provider, submits the request for sending

4. The SMS service provider sends the information to the user's mobile phone through the operator
Second: Mobile phone number SMS verification foreground page effect implementation

<!    DOCTYPE html>

Third, call SMS Server SMS Interface

<?php/** * Created by PhpStorm. * User: Leo * Date: 2017/8/30 * Time: 14:59 *///$_post$phone= isset($_POST[‘phone‘])?$_POST[‘phone‘]:‘‘;$code = isset($_POST[‘code‘])?$_POST[‘code‘]:‘‘;require (dirname(__FILE__).‘/config.php‘);require (dirname(__FILE__).‘/SendSMS.php‘);//实例化短信发送类$sms= new SendSMS($options[‘account‘],$options[‘password‘]);$context=‘验证码‘.$code;$res=$sms->send($phone,$context);if ($res){ echo "成功";}else{ echo "失败";}

Because we write the code separately for the sake of the elegance of the code. It is convenient to reuse later. So the sending of short messages specifically encapsulates a class. See the code specifically:

  <?php/** * Created by Phpstorm. * User:leo * DATE:2017/8/30 * time:15:26 *//** * Set User information */class sendsms{ Const sendurl= ' http://gd.ums86.com:8899/sms/Api/Send.do '; Private $_un; Private $_PW; function __construct ($user, $pwd) {$this->_un= $user; $this->_pw= $pwd; } function Send ($phone, $content, $isreport =0) {//Send data $data =array (' un ' = $this->_un, ' PW ' = $this->_pw, ' sm ' and ' $content, ' da ' and ' $phone, ' Rd ' and $isreport, ' RF ' =>2, ' TF ' =>3, ' DC ' =>15,); $url =sendsms::sendurl. '? '. Http_build_query ($data); $this->curlget ($url); Public Function Curlget ($url) {$ch = Curl_init (); curl_setopt ($ch, curlopt_header,0); curl_setopt ($ch, curlopt_returntransfer,1); curl_setopt ($ch, Curlopt_url, $url); $res =curl_exec ($ch); Curl_close ($ch); return $res; }}

In the sendsms inside of some methods, you in the third-party SMS verification code provider provided by the instance code inside can see, the function is basically the same, so we realize a belong to their own send message class, relatively simple.

Finally, we realized a message verification code to send the function of their own

So in the end, have you learned it?

PHP SMS Verification Code function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.