Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the function of sending CAPTCHA by php

Shulou Source: shulou.com Published: 2022-06-02 22:20:22 09月30日 Update

This article is about how php can send CAPTCHA. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Php to achieve the function of sending CAPTCHA: 1, create a good HTML and js files; 2, create a "Msm.php" file, the content is "public function sendmsm () {...}"; 3, send a HTTP request through CURL.

This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer

How does php achieve the function of sending CAPTCHA?

PHP implements sending SMS verification code:

1. Html code

Mobile phone number: CAPTCHA: get CAPTCHA

II. Js code

/ * send verification code * @ return {[type]} [description] * / function get_svg () {var phone = $("input [name = 'telephone']") .val (); if (! (/ ^ 1 [34578]\ d {9} $/ .test (phone) {layer.msg ("Please enter your cell phone number correctly!") ; return false;} var url = "/ msm/sendmsm/phone/" + phone;$.get (url, function (resdata) {console.log (resdata); layer.msg (resdata.data); if (resdata.type = = 1) {$(".code _ btn"). Attr ('onclick', "return false;"); listion_sendmsm ();}) return false;} function listion_sendmsm () {var time = 61 SetTime = setInterval (function () {if (time $conf ['msm_appkey'],' password' = > $conf ['msm_secretkey'],' msg' = > urlencode ($content), 'phone' = > $telephone,'report' = > true); $result = $this- > curlPost ("http://smssh2.253.com/msg/send/json", $postArr); $json = json_decode ($result); if ($json-> code! = 0) {return false;} else {return true }} / * send HTTP request via CURL * @ param string $url / / request URL * @ param array $postFields / / request parameters * @ return mixed * * / private function curlPost ($url,$postFields) {$postFields = json_encode ($postFields); $ch = curl_init (); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_HTTPHEADER, array ('Content-Type: application/json) Charset=utf-8' / / json version requires Content-Type: application/json;); curl_setopt ($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postFields); curl_setopt ($ch, CURLOPT_TIMEOUT,60); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0) $ret = curl_exec ($ch); if (false = = $ret) {$result = curl_error ($ch);} else {$rsp = curl_getinfo ($ch, CURLINFO_HTTP_CODE); if (200! = $rsp) {$result = "request status". $rsp. "". Curl_error ($ch);} else {$result = $ret;}} curl_close ($ch); return $result;}

Thank you for reading! This is the end of this article on "how php can send CAPTCHA". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Authentication code SMS function interface content mobile phone parameter just number mobile number file more article reference input good practical successful mobile number Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Information Apple MySQL vpn