Home > Backend Development > PHP Tutorial > PHP sends SMS verification code to complete the registration function, send SMS verification code_PHP tutorial

PHP sends SMS verification code to complete the registration function, send SMS verification code_PHP tutorial

WBOY
Release: 2016-07-12 09:04:03
Original
1085 people have browsed it

php sends SMS verification code to complete the registration function. Send SMS verification code

SMS verification code registration is very simple. It uses the SMS system of Yun Communication (chargeable, but there is The test API is used for testing by us). Okay, without further ado, let’s get to the point.

1. After receiving the registered account in the Cloud Communication SMS system, download their packaged SMS api interface code, unzip it, and then find the CCPRestSDK.php file and SendTemplateSMS.php file and pull it to the root folder.

2. Open the SendTemplateSMS.php file. First, pay attention to include_once('./CCPRestSDK.php'). Be sure not to include the wrong path. Fill in the test main account, main account Token, and application ID given by Cloud Communication here. among three variables.

3. Create the sendMessage.html page (no excessive security filtering is done here)

<span style="font-family: 'Microsoft YaHei'; font-size: 16px;"><!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Index</title>
<script type="text/javascript" src="jquery.min.js"></script>
</head>
   
<body>
  <form action="reg.php" method="post">
    手机号:<input type="text" name="tel" id="tel"><br>
    验证码:<input type="text" name="verify" id=""><span><button id="btn" type="button">免费发送验证码</button></span><br>
    <input type="submit" name="" value="注册"> 
  </form>
  <script type="text/javascript">
    $('#btn').click(function(){
      var tel = $.trim($('#tel').val());
      $.post('SendTemplateSMS.php', {'tel':tel},function(res){
        if (res) {
          alert('发送成功');
        } else {
          alert('发送失败');
        }
      });
    });
  </script>
</body>
</html> 
</span>
Copy after login

4. Enter your mobile phone number and click to send the verification code for free, and check if the verification code has been sent successfully

5. The mobile phone number has been written in the SendTemplateSMS.php file and then processed

<span style="font-family: 'Microsoft YaHei'; font-size: 16px;">  $tel = $_POST['tel'];
  $res = sendTemplateSMS($tel, array($verify, 2),"1");  //$verify是所包含的verify.php文件里动态生成的四位数字验证码变量,生成时已将验证码存于SESSION里 ,到提交验证码时用于验证判断
  if ($res) {
    echo '1';
  } else {
    echo '0';
  }
</span>
Copy after login

6. If nothing goes wrong, the phone will receive a four-digit verification code, then enter the verification code and submit it to the reg.php file

7. Logically verify whether the verification code is correct in the reg.php file* (I am just doing an experiment, so I haven’t done much security filtering)

<span style="font-family: 'Microsoft YaHei'; font-size: 16px;"><&#63;php
  session_start();
 
  $tel = $_POST['tel'];
  $ver = trim($_POST['verify']);
 
  if ( $ver == $_SESSION['verify']) {
    echo '验证码正确';
  } else {
    echo '验证码有误';
  }
 
 &#63;>
</span>
Copy after login

8. The result output verification code is correct

The entire verification code verification logic is so simple. I hope it can help everyone successfully complete the SMS verification code verification and realize the registration function.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1075082.htmlTechArticlephp sends SMS verification code to complete the registration function. Send SMS verification code and SMS verification code to register. It is very simple. Use Cloud Communication’s SMS system (charged, but there is a test API for us...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template