當前位置:首頁 » 編程語言 » php驗證碼怎麼做

php驗證碼怎麼做

發布時間: 2022-08-18 07:52:07

『壹』 php中發送簡訊驗證碼的步驟和方法是怎麼樣的

生成隨機字元串-》插入到資料庫(資料庫表應該有發送到簡訊手機號碼,隨機字元串,失效時間,添加時間等欄位)-》發送隨機字元串簡訊到手機號碼上(根據簡訊介面實現php一般用webservice)-》ajax比較用戶填寫的驗證碼與資料庫保存的是否一樣

『貳』 PHP製作注冊頁面驗證碼

使用view-source:查看源碼會有錯誤提示,所以導致圖片無法正常輸出

『叄』 php的驗證碼提示怎樣製作

一般製作驗證碼會按照下面的幾步走:
一:創建出來一個圖片,通常我們成為源,可以用imagecreatetruecolor()這個函數搞定
二:給這個源 添加背景色,同時設置文本顯示的顏色,GD庫函數為我們提供了imagecolorallocate()函數
三:材料弄好了,我們要給它添點內容了,就是我們隨機生成的數字或者字母,甚至可以是它們的組合,這里我們可以選擇兩個函數 imagettftext()、imagesrting(),這兩個函數的不同,我們會在後面講解。
例:
<?php
session_start();//開啟session,用來記錄獲得的驗證碼,這個函數要寫在程序的開頭,不然會出現錯誤
header(「Content-type :image/gif」);//把文件的返回類型設為image/gif格式,這個格式可以輸出圖片
$codelen=4;//設置你要讓用戶輸入字元的個數,一般為4,過長用戶體驗不好。
$charset =」ABCDEFGHKLMNPRSTUVWYZ23456789″;//我們可以盡量把一些難以辨認的字元去掉,比如阿拉伯數字0和字母o,這也是提高用戶體驗的一種方法。
$code =」;
for($i=0;$i<$codelen;$i++){//用for循環得到4個隨機的字元,在這里用到了mt_rand,這個函數比rand的效率要高的多,建議大家用這個
$code .=$charset{mt_rand(0,strlen($charset)-1)};
}
$_SESSION['code']=$code;//下篇關於session驗證的文章將會用到
$width = 80;
$height = 40;
$im = imagecreatetruecolor($width,$height);//用imagecreatetruecolor()函數來建立一個新的圖片,裡面的兩個數值分別是寬度和高度,這是製作驗證碼的第一步
$bg = imagecolorallocate($im,255,255,0); //圖片背景的顏色,這里是第二步
$textcolor = imagecolorallocate($im,255,0,0);//文字的顏色
imagefill($im,0,0,$bg);//給圖片填充背景色
//好了上面的鋪墊任務做的差不多了,現在關鍵就是讓字元顯示在圖片上,這里有兩種方法我們一一介紹。
$font =」ggbi.ttf」;//如果你有字體的話 就填上字體的相對路徑,如果沒有就留空。下面的兩個用法我會一一講解。
if($font!==」"){
for($num=0;$num<4;$num++){
imagettftext($im,mt_rand(12,16),(mt_rand(0,75)+330)%360,5+15*$num,20+mt_rand(2,5),$textcolor,$font,$code[$num]);//這里是第三步
}
}
else{
for($num=0;$num<4;$num++){
imagestring($im,5,10+15*$num,10+mt_rand(0,5),$code[$num],$textcolor);
}
}
header(「Content-type: image/jpeg」);
imagejpeg($im);
?>

『肆』 怎樣製作PHP驗證碼

<?php
//驗證碼:文本類型為圖像
header("content-type:image/png");
define('TYPE',3);//1.字母 2.字母數字 3.數字 4.邏輯 5.漢字
session_start();
//創建畫布
$img = imagecreatetruecolor(90,33);
//創建顏色
//$bgcolor = imagecolorallocate($img,rand(200,255),rand(200,255),rand(200,255));
$bgcolor = imagecolorallocate($img,255,255,255);
$textcolor = imagecolorallocate($img,rand(0,100),rand(0,100),rand(0,100));
//填充顏色到畫布
imagefill($img,0,0,$bgcolor);
//創建但像素的點為干擾項
//for($i=0;$i<100;$i++){
// $pixelcolor = imagecolorallocate($img,rand(150,200),rand(150,200),rand(150,200));
// imagesetpixel($img,rand(0,70),rand(0,30),$pixelcolor);
//}
//
////劃線
//$linecolor = imagecolorallocate($img,255,0,0);
//imageline($img,0,0,70,30,$linecolor);
//
////多邊形
// $col_poly = imagecolorallocate ( $img , 0 , 255 , 0 );
// imagepolygon ( $img ,
// array (
// 5 , 5,
// 5, 15 ,
// 20,15,
// 20,5
// ),
// 4 ,
// $col_poly );
////弧線
//$arcColor = imagecolorallocate ( $img , 0 , 0 , 255 );
//imagearc($img,35,15,30,30,0,360,$arcColor);

//創建驗證碼的內容
//#字母
$letter = range('A','Z');
$letterStr = $letter[rand(0,25)].$letter[rand(0,25)].$letter[rand(0,25)].$letter[rand(0,25)];
//數字字母
$num = range(0,9);
$numberAndLetter = array_merge($letter,$num);
$nal = $numberAndLetter[rand(0,35)].$numberAndLetter[rand(0,35)].$numberAndLetter[rand(0,35)].$numberAndLetter[rand(0,35)];
//#數字
$number = rand(1000,9999);
//#邏輯
$x = rand(1,9);
$y = rand(1,9);
$expression = $x."+".$y."=?";
$sum = $x+$y;
//#漢字
$CH = array('恭喜發財','財源滾滾','財源廣進','才高八斗','學富五車','抬頭見喜');
$chstr = $CH[rand(0,count($CH)-1)];
switch(TYPE){
case 1 : imagettftext($img,14,0,7,23,$textcolor,'MSYH.TTF',$letterStr);$_SESSION['code']=$letterStr;break;
case 2 : imagettftext($img,14,0,7,23,$textcolor,'MSYH.TTF',$nal);$_SESSION['code']=$nal;break;
case 3 : imagettftext($img,14,0,13,23,$textcolor,'MSYH.TTF',$number);$_SESSION['code']=$number;break;
case 4 : imagettftext($img,14,0,7,23,$textcolor,'MSYH.TTF',$expression);$_SESSION['code']=$sum;break;
case 5 : imagettftext($img,11,0,6,21,$textcolor,'MSYHBD.TTF',$chstr);$_SESSION['code']=$chstr;break;
}
//輸入圖像到瀏覽器
imagepng($img);
?>

『伍』 我的php代碼中登陸界面加一個驗證碼,如何實現

php登陸頁面+驗證碼的實現,參考如下:

1、首先新建一個php站點;

『陸』 php怎麼編寫手機簡訊驗證碼功能

以前在遠標做過你的應用應該是這樣吧,用戶輸入手機號碼,點擊發送簡訊,用戶收到驗證碼,輸入對應的驗證碼 判斷是否正確。

需要:
申請一個簡訊介面,就是點擊發送驗證碼的時候,提交到介面給該號碼下發驗證碼。

技術方面的實現:
1、點擊獲取驗證碼
2、程序ajax post提交到簡訊介面
3、簡訊介面服務商 介面判斷用戶和口令,正確後,下發簡訊給該號碼。
4、用戶輸入號碼,程序判斷驗證碼是否一致。

『柒』 php驗證碼怎麼使用

把以上代碼保存成code.php,上傳到相應目錄,如網站根目錄 調用的時候 <img src="code.php"> 即可

『捌』 PHP 驗證碼怎樣設置

補充:

驗證碼可以同cookie或者session的方式傳遞數據,
不用有特別的設置,不過要安裝GD庫,否則不能顯示圖片.

隨便放在哪裡都可以,

顯示是以圖片方式顯示,

例如驗證碼的程序文件是ck.php

那麼顯示就是
<img src = "ck.php">

驗證碼有很多種編寫方式,當然是眾說紛紜,
凡是程序都不會有一個統一的格式,只有統一的思路.

『玖』 如何實現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();

}

熱點內容
天賜良緣1期門禁密碼是多少 發布:2024-04-23 17:22:26 瀏覽:309
引流腳本什麼意思 發布:2024-04-23 17:16:49 瀏覽:396
江叔常用的密碼是多少 發布:2024-04-23 17:11:54 瀏覽:594
內存儲存公司股票 發布:2024-04-23 16:57:16 瀏覽:929
linuxrootkit 發布:2024-04-23 16:56:37 瀏覽:325
線索一這廁所的密碼是多少 發布:2024-04-23 16:48:44 瀏覽:573
河源中考成績查詢密碼是什麼 發布:2024-04-23 16:48:42 瀏覽:607
ipad解壓視頻文件 發布:2024-04-23 16:47:44 瀏覽:137
順序表是線性表的什麼存儲結構 發布:2024-04-23 16:32:28 瀏覽:455
腳本刷皮膚 發布:2024-04-23 16:12:25 瀏覽:858