導航:首頁 > 編程語言 > php實現動態驗證碼

php實現動態驗證碼

發布時間:2022-07-26 03:37:15

A. 我想在我的php網站里加一個驗證碼,滑動那種

你也真敢想。
網頁驗證碼一般是在後台生成一個驗證碼在後台生成好圖片返回給網頁顯示,用戶輸入的信息與後端保存的信息再進行驗證。
如果後端的信息返回到前端是已文字的形式,就起不到安全的作用了。
你的這個功能可以這樣設計,但作用不大。我來說說我的思路吧
首先後端返回一個數字類型的驗證碼,前端獲取數字行的驗證用js+css組織實現特效。你在上圖的黑色部分設定一個擋扳的html元素(這個元素距離左邊的三角形滑動塊的距離就是後端返回的數字),左邊滑塊滑動多少距離達這個隱藏區塊,獲取這個數值,保存下來。

B. 怎樣製作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);
?>

C. php怎麼編寫手機簡訊驗證碼功能

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

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

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

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

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

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

E. php實現驗證碼,能給具體的代碼嗎 在這謝謝過各位高手了

index.php:
<?php
/* index.php start*/
if(!empty($_POST)) {
session_start();
if($_POST['seccode'] == $_SESSION['seccode']) {
echo '<script>alert("驗證成功")</script>';
} else {
echo '<script>alert("驗證失敗")</script>';
}
session_destroy();
}
?>
<form action="" method="post" />
<img id="seccode" src="seccode.php?rand=".<?=rand()?> /> <input type="text" name="seccode" /> <input type="submit" value="submit" />
<input type="button" onclick="document.getElementById('seccode').src = 'seccode.php?reload=1&' + Math.random()" value="change one"/>
</form>

<?php
/* index.php end*/
?>

******************************
seccode.php:
<?php
/*seccode.php start*/
session_start();
if(isset($_SESSION['seccode']) && empty($_GET['reload'])) {
$arr = $_SESSION['seccode'];
} else {
for($i=0; $i<4; $i++) {
$arr[] = rand(0, 9);
}
$_SESSION['seccode'] = implode($arr);
}
$im = imagecreate(90, 25);
$backgroundcolor = imagecolorallocate ($im, 255, 255, 255);

for($i = 0; $i < 4; $i++) {
$s = iconv('GBK', 'UTF-8', $arr[$i]);
$x = $i * 20 + mt_rand(0, 4) - 2;// 隨機X
$y = mt_rand(0, 4); // 隨機Y
$angle = mt_rand(0,4);// 隨機角度
$text_color = imagecolorallocate($im, mt_rand(50, 255), mt_rand(50, 128), mt_rand(50, 255)); // 隨機顏色
imagettftext($im,20, $angle,$x,20+$y,$text_color,"C:\\Windows\\Fonts\\SIMSUN.TTC",$s);
}

// 線條
$linenums = mt_rand(10, 32);
for($i=0; $i <= $linenums; $i++) {
$linecolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
$linex = mt_rand(0, 62);
$liney = mt_rand(0, 25);
imageline($im, $linex, $liney, $linex + mt_rand(0, 4) - 2, $liney + mt_rand(0, 4) - 2, $linecolor);
}

// 雜點
for($i=0; $i <= 64; $i++) {
$pointcolor = imagecolorallocate($im, mt_rand(50, 255), mt_rand(50, 255), mt_rand(50, 255));
imagesetpixel($im, mt_rand(0, 62), mt_rand(0, 25), $pointcolor);
}

// 邊框
$bordercolor = imagecolorallocate($im , 150, 150, 150);
imagerectangle($im, 0, 0, 89, 24, $bordercolor);

header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
/*seccode.php end*/
?>

F. 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);
?>

G. 如何在html+php上實現數字動態變更 是這樣的 比如一個數字A=50 我在一個表單(輸入框)

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標題文檔</title>

</head>
<script type="text/jscript">
window.onload=function(){//頁面載入完成後執行函數
var input=document.getElementById("input");//根據id獲得輸入框對象
var show_input=document.getElementById("value");//根據id獲得顯示輸入內容的對象
input.onkeyup=function(){//在輸入框松開鍵盤按鍵時執行函數
if(input.value!=""){//如果這個時候輸入框里有值則先顯示輸入值,否則顯示請輸入數據
show_input.innerHTML="你輸入的數據為"+input.value;
}else{
show_input.innerHTML="請輸入數據"+input.value;
}
}
}
</script>
<body>
<input type="text" id="input" value="" />
<span id="value">請輸入數據</span>
</div>
</body>
</html>

H. 驗證碼怎麼用php實現

<?php
/*
* Filename: authpage.php
*/

srand((double)microtime()*1000000);

//驗證用戶輸入是否和驗證碼一致
if(isset($HTTP_POST_VARS['authinput']))
{
if(strcmp($HTTP_POST_VARS['authnum'],$HTTP_POST_VARS['authinput'])==0)

echo "驗證成功!";
else
echo "驗證失敗!";
}

//生成新的四位整數驗證碼
while(($authnum=rand()%10000)<1000);
?>
<form action=authpage.php method=post>
<table>
請輸入驗證碼:<input type=text name=authinput style="width:
80px"><br>
<input type=submit name="驗證" value="提交驗證碼">
<input type=hidden name=authnum value=<? echo $authnum; ?>>
<img src=authimg.php?authnum=<? echo $authnum; ?>>
</table>
</form>

代碼二:

<?php
/*
* Filename: authimg.php
* Author: hutuworm
* Date: 2003-04-28
* @Copyleft hutuworm.org
*/

//生成驗證碼圖片
Header("Content-type: image/PNG");
srand((double)microtime()*1000000);
$im = imagecreate(58,28);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im, 200,200,200);
imagefill($im,68,30,$gray);

//將四位整數驗證碼繪入圖片
imagestring($im, 5, 10, 8, $HTTP_GET_VARS['authnum'], $black);

for($i=0;$i<50;$i++) //加入干擾象素
{
imagesetpixel($im, rand()%70 , rand()%30 , $black);
}

ImagePNG($im);
ImageDestroy($im);
?>

I. 怎麼用原生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);
}
}
?>
字體自己去找,修改下路徑就行了

J. 請教網頁製作中PHP驗證碼實現問題。

在文件1用表單提交給文件2,輸入驗證碼肯定是在表單的輸入框里,輸入好後提交表單時對象是文件2就行了。注意php需要伺服器支持啊,沒伺服器直接當文本打開了。

閱讀全文

與php實現動態驗證碼相關的資料

熱點內容
為什麼空氣難壓縮是因為斥力嗎 瀏覽:641
郭天祥單片機實驗板 瀏覽:599
伺服器有什麼危害 瀏覽:256
飢荒怎麼開新的獨立伺服器 瀏覽:753
文件夾變成了 瀏覽:560
linuxpython綠色版 瀏覽:431
怎麼下載小愛同學音箱app 瀏覽:554
python佔位符作用 瀏覽:76
javajdbcpdf 瀏覽:543
php網頁模板下載 瀏覽:192
python試講課pygame 瀏覽:409
安居客的文件夾名稱 瀏覽:677
家裡伺服器如何玩 瀏覽:451
網站源碼使用視頻 瀏覽:748
stc89c52單片機最小系統 瀏覽:452
郵件安全證書加密 瀏覽:416
雲伺服器如何訪問百度 瀏覽:279
常州電信伺服器dns地址 瀏覽:839
用小方塊製作解壓方塊 瀏覽:42
圖像壓縮編碼實現 瀏覽:68