php製作驗證碼

2021-07-11 13:59:03 字數 968 閱讀 7819

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

1 執行**前請把php 的gd庫開啟;

2 驗證碼應該去除不易區分的字元 比如 2 和z ,1 和字母l ,0和 字母o等等

imagecreatetruecolor

imagecolorallocate

imagesetpixel

imageline

imagestring

imagettftext

<?php

/** * created by phpstorm.

* user: alex

* date: 2016/5/3

* time: 16:59

*//**

*@param $width

*@param $height

*@param $codenum

*/function

identifycoding

($width, $height, $codenum)

$linecolor = imagecolorallocate($image, mt_rand(50, 200), mt_rand(50, 210), mt_rand(50, 250));

for ($k = 0; $k

< 5; $k++)

for ($i = 0; $i

< $codenum; $i++)

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

imagepng($image);

}identifycoding(500, 100, 4);

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 驗證碼製作

session儲存驗證資訊 漢字驗證碼實現 實現 驗證碼1.在製作驗證碼之前請確認php的gd庫 影象處理庫 是否開啟。phpinfo 檢視 2.在輸出影象之前,一定要在先設定header content type image png 3.在給驗證碼字元顏色取值的時候一般r g b的取值在0 120...