您好,登錄后才能下訂單哦!
1.表單傳輸頁面
<?php session_start(); error_reporting(E_ALL & ~E_NOTICE); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>手機驗證碼</title> <? $action=$_GET["action"]; if ($action=='add') { if ((strtotime($_SESSION['time']) + 60) < time()) {//將獲取的緩存時間轉換成時間戳加上60秒后與當前時間比較,小于當前時間即為過期 session_destroy(); unset($_SESSION); //header('content-type:text/html; charset=utf-8;'); echo '<script>alert("驗證碼已過期,請重新獲取!");</script>'; } else { $Code = trim($_POST["TextBox2"]); if (strlen($Code) > 1 and $Code == $_SESSION['rand']) print("<script>alert('驗證成功')</script>"); else print("<script>alert('驗證失敗')</script>"); unset($_SESSION['rand']); } } ?> <script src="js/jquery.js" language="javascript" type="text/javascript"></script> <script type="text/javascript"> function get(obj) { var partten = /^\d{10,13}$/; if (!partten.test(document.getElementById("TextBox1").value)) { alert('請輸入正確的手機號碼'); return; } obj.disabled = true; $.ajax({ url: "getcode.php", type: "Post", data: "Tel=" + $("#TextBox1").val(), success: function(msg) { obj.disabled = false; if (msg == "ok") { alert("111") return; } if (msg == "error") { alert("22") return; } alert(msg); } }) } </script> </head> <body> <label> <form id="form1" name="form1" method="post" action="index.php?action=add"> 您手機號碼: <input name="TextBox1" type="text" id="TextBox1" /> <input id="Button1" type="button" value="獲取短信驗證碼" onClick="get(this)" /> <br /> <br /> 驗證碼: <input name="TextBox2" type="text" id="TextBox2" /> </label> <br /> <br /> <label> <input type="submit" name="Submit" value=" 確 定 " /> </label> </form> <p> </p> </body> </html>
2.數據處理頁面,(發送短信驗證)
<?php session_start(); include "TopSdk.php"; date_default_timezone_set('Asia/Shanghai'); //生成隨機驗證碼 $srand = rand(1000,9999); $_SESSION['rand']=$srand; //生成緩存時間 if (isset($_SESSION['time']))//判斷緩存時間 { $_SESSION['time']; } else { $_SESSION['time'] = date("Y-m-d H:i:s"); } $rand = $_SESSION['rand']; $c = new TopClient; $appkey = 'XXX';//你的appkey $secret = 'XXXX';//你的secret //$phone = 'XXXXXX'; $phone=$_POST["Tel"];//得到的手機號 $c->appkey = $appkey; $c->secretKey = $secret; $req = new AlibabaAliqinFcSmsNumSendRequest; $req->setExtend(""); $req->setSmsType("normal"); $req->setSmsFreeSignName("XX");//你的短信驗證簽名 $req->setSmsParam("{number:'$rand'}"); $req->setRecNum($phone); $req->setSmsTemplateCode("XX");//你的短信模板ID $resp = $c->execute($req); ?>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。