php 驗證碼 的製作 (個人學習筆記)

2021-06-17 23:14:15 字數 1180 閱讀 3345

鏈結自:php討客網

驗證頁面截圖如下:

(輸入結果 回車後會出現結果)

html頁

result.php 結果頁

<?php 

session_start();

?>

<?php

if(strtoupper($_post['yzm'])==$_session['yzm'])else

?>

yzm.php 驗證頁

<?php 

session_start();

$width=100;

$height=30;

$img=imagecreate($width,$height);

$bg=imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)); //生成背景顏色

$color=imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));//生成字型顏色imagecolorallocate() 用來生成顏色 第一次生成背景顏色 引數 (影象,紅,綠,藍)

$a=mt_rand(0,9);

$b=mt_rand(0,9);//隨機在0-9之間 生成乙個數字

$result=$a+$b;

$text=$a.'+'.$b.'=';

imagettftext($img,20,0,10,20,$color,'font/simkai.ttf',$text);//引數(,字型大小,傾斜角度,x軸,y軸,字型顏色,字型**,文字內容) imagettftext()函式

imagejpeg($img);

$_session['yzm']=$result;

header("content-type:image/png");

?>

php 驗證碼製作

直接上 function buildrandomstring type 1,length 4 else if type 2 else if type 3 if length strlen chars 隨意打亂字串 chars str shuffle chars return substr chars...

php製作驗證碼

session start 型別 type gif 的尺寸 width 40 height 16 header content type image type srand double microtime 1000000 生成字元的個數 randval randstr 4,if type gif f...

php製作驗證碼

用php製作乙個一串驗證碼很簡單,主要需要用到一下函式,到手冊上查詢下就知道了,需要注意imagettftext,需要乙個字型檔案,我在win7控制面板字型裡拷貝出來的.這個函式比imagestring 好一點是因為,可以改變字型,和字型大小,imagestring只提供內建的字型大小1,2,3,4...