① php 簡訊驗證碼資料庫如何設計
php做簡訊驗證碼,需要將手機號,發送的驗證碼和時間這幾個存到資料庫,在添加到資料庫的時候,要判斷裡面有沒有要存的手機號,有的話,就更新驗證碼和時間,沒有就是添加,在使用驗證碼判定的時候,取出驗證碼和時間,判斷驗證碼是否正確,時間是否在自己設置的有效時間段內,整個過程就是這樣。
② php中發送簡訊驗證碼的步驟和方法是怎麼樣的
生成隨機字元串-》插入到資料庫(資料庫表應該有發送到簡訊手機號碼,隨機字元串,失效時間,添加時間等欄位)-》發送隨機字元串簡訊到手機號碼上(根據簡訊介面實現php一般用webservice)-》ajax比較用戶填寫的驗證碼與資料庫保存的是否一樣
③ 注冊時接到手機簡訊驗證是怎麼實現的
手機注冊驗證邏輯是這樣的:
首先要找簡訊服務商如:夢網、雲信使、互億無線等等申請簡訊發送介面。
網站實現流程如下:
第一步:用戶注冊時輸入手機號,網站首先要通過JS或者ajax+php驗證這個號碼是不是正確的手機號。
第二步:用戶點擊發送手機驗證碼,通過ajax把手機號傳到php,這時php生成一個隨機的驗證碼保存在session中,然後通過簡訊介面把這個驗證碼發送到這個手機號中。
第三步:用戶輸入手機收到的驗證碼注冊。網站用session中的驗證碼和用戶輸入的驗證碼比較。
④ php怎麼編寫手機簡訊驗證碼功能
以前在遠標做過你的應用應該是這樣吧,用戶輸入手機號碼,點擊發送簡訊,用戶收到驗證碼,輸入對應的驗證碼 判斷是否正確。
需要:
申請一個簡訊介面,就是點擊發送驗證碼的時候,提交到介面給該號碼下發驗證碼。
技術方面的實現:
1、點擊獲取驗證碼
2、程序ajax post提交到簡訊介面
3、簡訊介面服務商 介面判斷用戶和口令,正確後,下發簡訊給該號碼。
4、用戶輸入號碼,程序判斷驗證碼是否一致。
⑤ 用PHP寫一個介面,隨機生成6位數字,然後以簡訊的形式發送到對應的手機號上。從來沒寫過介面不知道如何寫
簡訊介面需要你有對應的簡訊服務商才行,通常是第三方簡訊服務商,這種服務往往是收費的,收取的費用越多,每天可以發送的簡訊數量越多。
你需要向他們申請簡訊介面,申請成功後會有介面文檔,按照文檔中的規定發送相應的數據即可,通常發送的數據包含:需要發送簡訊的手機號、簡訊內容。
介面寫法通常會在文檔中有寫,甚至有的文檔會附帶範例以供開發者參考。
⑥ 怎樣用PHP製作驗證碼
<?php
//驗證碼類
classValidateCode{
private$charset='';//隨機因子
private$code;//驗證碼
private$codelen=4;//驗證碼長度
private$width=90;//寬度
private$height=40;//高度
private$img;//圖形資源句柄
private$font;//指定的字體
private$fontsize=20;//指定字體大小
private$fontcolor;//指定字體顏色
//構造方法初始化
publicfunction__construct(){
$this->font=dirname(__FILE__).'/font/elephant.ttf';//注意字體路徑要寫對,否則顯示不了圖片
}
//生成隨機碼
privatefunctioncreateCode(){
$_len=strlen($this->charset)-1;
for($i=0;$i<$this->codelen;$i++){
$this->code.=$this->charset[mt_rand(0,$_len)];
}
}
//生成背景
privatefunctioncreateBg(){
$this->img=imagecreatetruecolor($this->width,$this->height);
$color=imagecolorallocate($this->img,mt_rand(157,255),mt_rand(157,255),mt_rand(157,255));
imagefilledrectangle($this->img,0,$this->height,$this->width,0,$color);
}
//生成文字
privatefunctioncreateFont(){
$_x=$this->width/$this->codelen;
for($i=0;$i<$this->codelen;$i++){
$this->fontcolor=imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imagettftext($this->img,$this->fontsize,mt_rand(-30,30),$_x*$i+mt_rand(1,5),$this->height/1.4,$this->fontcolor,$this->font,$this->code[$i]);
}
}
//生成線條、雪花
privatefunctioncreateLine(){
//線條
for($i=0;$i<6;$i++){
$color=imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imageline($this->img,mt_rand(0,$this->width),mt_rand(0,$this->height),mt_rand(0,$this->width),mt_rand(0,$this->height),$color);
}
//雪花
for($i=0;$i<100;$i++){
$color=imagecolorallocate($this->img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
imagestring($this->img,mt_rand(1,5),mt_rand(0,$this->width),mt_rand(0,$this->height),'*',$color);
}
}
//輸出
privatefunctionoutPut(){
header('Content-type:image/png');
imagepng($this->img);
imagedestroy($this->img);
}
//對外生成
publicfunctiondoimg(){
$this->createBg();
$this->createCode();
$this->createLine();
$this->createFont();
$this->outPut();
}
//獲取驗證碼
publicfunctiongetCode(){
returnstrtolower($this->code);
}
}
⑦ 求助,哪位大神給說一下,php簡訊驗證碼表結構設計
id 自增
mobile 手機號
code 驗證碼
add_time 生成時間
status 使用狀態:1為已使用,0為未使用,默認為0
以上為最簡單的結構,需求不復雜應該就夠用的了,add_time可以用於判斷是否過期,status可以用於判斷是否已經使用,要是重新發送驗證碼的話,就把前面的記錄刪除掉。如果多個功能用到驗證碼的話,弄個type欄位來區分功能
⑧ 怎麼用原生php做驗證碼
<?php
class validateCode{
private $charset=''; //隨機因子
private $_len;
private $code; //驗證碼
private $codelen=4; //驗證碼長度
private $width=130; //畫布寬度
private $height=50; //畫布長度
private $img; //圖形資源句柄
private $font; //制定字體
private $fontsize=26;//字體大小
private $fontcolor; //字體顏色
//初始化構造函數
public function __construct(){
$this->font=dirname(__file__).'/validateFont.ttf';
//字體文件及路徑,__file__表示當前PHP文件絕對路徑,dirname表示這個PHP文件的絕對路徑的上一層
}
//生成隨機碼
private function createCode(){
$this->_len=strlen($this->charset)-1; //strlen表示計算字元串長度
for($i=1;$i<=$this->codelen;$i++){
$this->code.=$this->charset[mt_rand(0,$this->_len)];
}
}
//生成背景
private function createBG(){
$this->img=imagecreatetruecolor($this->width,$this->height);//創建圖像
$color=imagecolorallocate($this->img,mt_rand(157,255),mt_rand(157,255),mt_rand(157,255)); //分配顏色函數(紅,綠,藍)
imagefilledrectangle($this->img,0,$this->height,$this->width,0,$color); //矩形區域著色函數(要填充的圖像,x1,y1,x2,y2,要填充的顏色),x1,y1,x2,y2表示矩形的對角線
}
//生成文字
private function createFont(){
$_x=$this->width/$this->codelen;
for($i=0;$i<$this->codelen;$i++){
$this->fontcolor=imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imagettftext($this->img,$this->fontsize,mt_rand(-30,30),$_x*$i+mt_rand(1,5),$this->height/1.4,$this->fontcolor,$this->font,$this->code[$i]); //參數 size 為字形的尺寸;angle 為字型的角度,順時針計算,0 度為水平,也就是三點鍾的方向 (由左到右),90 度則為由下到上的文字;x,y 二參數為文字的坐標值 (原點為左上角);參數 col 為字的顏色;fontfile 為字型文件名稱,亦可是遠端的文件;text 當然就是字元串內容了。
}
}
//生成線條雪花
private function createLine(){
//線條
for($i=0;$i<6;$i++){
$color=imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imageline($this->img,mt_rand(0,$this->width),mt_rand(0,$this->height),mt_rand(0,$this->width),mt_rand(0,$this->height),$color);
}
//雪花
for($i=0;$i<40;$i++){
$color=imagecolorallocate($this->img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
imagestring($this->img,mt_rand(1,5),mt_rand(0,$this->width),mt_rand(0,$this->height),'*',$color);
}
}
//輸出
private function outPut(){
header("content-type:image/png");
imagepng($this->img);
imagedestroy($this->img);
}
//對外生成
public function doimg(){
$this->createCode();
$this->createBg();
$this->createFont();
$this->createLine();
$this->outPut();
}
//獲取驗證碼
public function getCode(){
return strtolower($this->code);
}
}
?>
字體自己去找,修改下路徑就行了
⑨ php獲取手機號與驗證碼往手機上發簡訊。
你流程搞錯了。應該是這樣子:
PHP生成驗證碼,存進SESSION。將驗證碼POST到移動API,用戶收到後,輸入驗證碼,和SESSION比對。
⑩ 如何實現php手機簡訊驗證功能
現在網站在建設網站時為了保證用戶信息的真實性,往往會選擇發簡訊給用戶手機發驗證碼信息,只有通過驗證的用戶才可以注冊,這樣保證了用戶的聯系信息資料的100%的准確性。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >
<html xmlns>
<head>
<title></title>
<script src="js/jquery-1.4a2.min.js" type="text/javascript"></script>
<script type="text/javascript">
/*-------------------------------------------*/
var InterValObj; //timer變數,控制時間
var count = 60; //間隔函數,1秒執行
var curCount;//當前剩餘秒數
var code = ""; //驗證碼
var codeLength = 6;//驗證碼長度
function sendMessage() {
curCount = count;
var dealType; //驗證方式
tel = $(』#tel』).val();
if(tel!=』』){
//驗證手機有效性
var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+d{8})$/;
if(!myreg.test($(』#tel』).val()))
{
alert(』請輸入有效的手機號碼!』);
return false;
}
tel = $(』#tel』).val();
//產生驗證碼
for (var i = 0; i < codeLength; i++) {
code += parseInt(Math.random() * 9).toString();
}
//設置button效果,開始計時
$("#btnSendCode").attr("disabled", "true");
$("#btnSendCode").val("請在" + curCount + "秒內輸入驗證碼");
InterValObj = window.setInterval(SetRemainTime, 1000); //啟動計時器,1秒執行一次
//向後台發送處理數據
$.ajax({
type: "POST", //用POST方式傳輸
dataType: "text", //數據格式:JSON
url: 』yanzhengma.php』, //目標地址(根據實際地址)
data: "&tel=" + tel + "&code=" + code,
error: function (XMLHttpRequest, textStatus, errorThrown) { },
success: function (msg){ }
});
}else{
alert(』請填寫手機號碼』);
}
}
//timer處理函數
function SetRemainTime() {
if (curCount == 0) {
window.clearInterval(InterValObj);//停止計時器
$("#btnSendCode").removeAttr("disabled");//啟用按鈕
$("#btnSendCode").val("重新發送驗證碼");
code = ""; //清除驗證碼。如果不清除,過時間後,輸入收到的驗證碼依然有效
}
else {
curCount--;
$("#btnSendCode").val("請在" + curCount + "秒內輸入驗證碼");
}
}
</script>
</head>
<body>
<input name="tel" id=tel type="text" />
<input id="btnSendCode" type="button" value="發送驗證碼" onclick="sendMessage()" /></p>
</body>
</html>
第三、調用簡訊伺服器簡訊介面
整理的頁面是yanzhengma.php(具體根據服務商提供信息)
<?php //提交簡訊
$post_data = array();
$post_data[』userid』] =簡訊服務商提供ID;
$post_data[』account』] = 』簡訊服務商提供用戶名』;
$post_data[』password』] = 』簡訊服務商提供密碼』;
// Session保存路徑
$sessSavePath = dirname(__FILE__)."/../data/sessions/";
if(is_writeable($sessSavePath) && is_readable($sessSavePath)){
session_save_path($sessSavePath);
}
session_register(』mobliecode』);
$_SESSION[』mobilecode』] = $_POST["code"];
$content=』簡訊驗證碼:』.$_POST["code"].』【簡訊驗證】』;
$post_data[』content』] = mb_convert_encoding($content,』utf-8』, 』gb2312』); //簡訊內容需要用urlencode編碼下
$post_data[』mobile』] = $_POST["tel"];
$post_data[』sendtime』] = 』』; //不定時發送,值為0,定時發送,輸入格式YYYYMMDDHHmmss的日期值
$url=』http://IP:8888/sms.aspx?action=send』;
$o=』』;
foreach ($post_data as $k=>$v)
{
$o.="$k=".$v.』&』;
}
$post_data=substr($o,0,-1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果需要將結果直接返回到變數里,那加上這句。
$result = curl_exec($ch);
?>
第四:提交表單信息時對簡訊驗證碼驗證
//手機驗證碼開始
session_start();
$svalitel = $_SESSION[』mobilecode』];
$vdcodetel = empty($vdcodetel) ? 』』 : strtolower(trim($vdcodetel));
if(strtolower($vdcodetel)!=$svalitel || $svalitel==』』)
{
ResetVdValue();
//echo "Pageviews=".$vdcodetel;
ShowMsg("手機驗證碼錯誤!", 』-1』);
exit();
}