Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of sending SMS CAPTCHA by PHP

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what is the method of PHP to send SMS CAPTCHA". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the method of sending SMS CAPTCHA by PHP"?

1. Create HTML and js files.

2. Create a "Msm.php" file with the content of "public function sendmsm () {...}".

3. Send a HTTP request through CURL.

Example

/ * send SMS * @ author * @ return [type] [description] * / public function sendmsm () {$phone = input ('phone'); if (! $phone) {return WPreturn (' Please enter your cell phone number!' ,-1);} $code = rand (1000 ~ 9999); $_ SESSION ['code'] = $code; $res = sendmessage ($code, $phone); if ($res) {return WPreturn (' sent successfully', 1);} else {return WPreturn ('failed to send CAPTCHA!' ,-1);}} / * Class name: ChuanglanSmsApi * function: blue-creating SMS API request class * details: construct blue-creating SMS API request to obtain remote HTTP data * description: * the following code is only sample code and uses a third-party blue SMS API to send SMS messages. * this code is for learning only and provides a reference only. * / public function sendmessage ($code, $telephone) {$conf = getconf (''); if (! $code) {return false;} if (! $telephone) {return false;} $content = "your verification code is: {$code}, if you do not do it yourself, please ignore this SMS." / / Blue-creating API parameters $postArr = array ('account' = > $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;} so far, I believe you have a deeper understanding of "what is the method of sending SMS CAPTCHA by PHP". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report