PHP Send SMS Verification Code complete registration function _php Instance

Source: Internet
Author: User

SMS Authentication Code registration, very simple, with the cloud communication SMS system (charge, but there are test API to do test for us). Well, don't say much, get to the point.

1, received the Cloud Communication SMS system registration account, and then download their encapsulated good SMS API interface code, decompression, and then find ccprestsdk.php files and sendtemplatesms.php files , Pull it into the root directory folder.

2, open sendtemplatesms.php file, the first attention to include_once ('./ccprestsdk.php '), do not include the wrong path, will cloud communication to the test master account, the main account token, application ID fill in these three variables.

3, create the Sendmessage.html page (here also did not do too much security filtering)

<span style= "font-family: ' Microsoft Yahei '; font-size:16px; " ><! DOCTYPE html>  

4, enter the mobile phone number click to send a free authentication code to see the success of the transmission

5, in the sendtemplatesms.php file has already written the mobile phone number and then processing code

<span style= "font-family: ' Microsoft Yahei '; font-size:16px; " >  $tel = $_post[' Tel '];
  $res = Sendtemplatesms ($tel, Array ($verify, 2), "1");  $verify is a dynamically generated four-bit digital authentication code variable in the contained verify.php file, which is stored in session during the generation, and is used to verify
  if ($res) {
    echo ' 1 ' when submitting the verification code)
  else {
    echo ' 0 ';
  }
</span>

6, if not an accident, the phone will receive a four-digit authentication code, and then enter the verification code to submit it to the reg.php file

7, reg.php file to verify the correctness of the code to verify the logic * (I just do the experiment, so did not do much security filtering processing)

<span style= "font-family: ' Microsoft Yahei '; font-size:16px; " ><?php
  session_start ();
 
  $tel = $_post[' Tel '];
  $ver = Trim ($_post[' verify ']);
 
  if ($ver = = $_session[' Verify ']) {
    echo ' captcha is correct ';
  } else {
    echo ' verification code is incorrect ';
  }
 
 ? >
</span>

8, the result output verification code is correct

The entire verification code verification logic is so simple, hope to help everyone smooth completion of the SMS Verification Code verification to achieve the registration 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.