PHP自定義大小驗證碼的方法詳解
更新時間:2013年06月07日 11:15:56 作者:
本篇文章是對PHP自定義大小驗證碼進行了詳細的分析介紹,需要的朋友參考下
復制代碼 代碼如下:
<?php
function vCode($num=4,$size=20, $width=0,$height=0){
!$width && $width = $num*$size*4/5+5;
!$height && $height = $size + 10;
// 去掉了 0 1 O l 等
$str = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVW";
$code = '';
for ($i=0; $i<$num; $i++){
$code.= $str[mt_rand(0, strlen($str)-1)];
}
// 畫圖像
$im = imagecreatetruecolor($width,$height);
// 定義要用到的顏色
$back_color = imagecolorallocate($im, 235, 236, 237);
$boer_color = imagecolorallocate($im, 118, 151, 199);
$text_color = imagecolorallocate($im, mt_rand(0,200), mt_rand(0,120), mt_rand(0,120));
// 畫背景
imagefilledrectangle($im,0,0,$width,$height,$back_color);
// 畫邊框
imagerectangle($im,0,0,$width-1,$height-1,$boer_color);
// 畫干擾線
for($i=0;$i<5;$i++){
$font_color = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
imagearc($im,mt_rand(-$width,$width),mt_rand(-$height,$height),mt_rand(30,$width*2),mt_rand(20,$height*2),mt_rand(0,360),mt_rand(0,360),$font_color);
}
// 畫干擾點
for($i=0;$i<50;$i++){
$font_color = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$font_color);
}
// 畫驗證碼
@imagefttext($im, $size , 0, 5, $size+3, $text_color, 'c://WINDOWS//Fonts//simsun.ttc',$code);
header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate");
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
}
?>
函數(shù)描述及例子:
<?
// 4個字符,大小為20
vCode(4,20);
?>
您可能感興趣的文章:
- php中文驗證碼實現(xiàn)示例分享
- PHP實現(xiàn)變色驗證碼實例
- 一個好用的PHP驗證碼類實例分享
- 生成隨機字符串和驗證碼的類的PHP實例
- PHP生成Gif圖片驗證碼
- PHP 驗證碼不顯示只有一個小紅叉的解決方法
- PHP驗證碼函數(shù)代碼(簡單實用)
- php生成圖形驗證碼幾種方法小結(jié)
- PHP生成驗證碼時“圖像因其本身有錯無法顯示”的解決方法
- 一個漂亮的php驗證碼類(分享)
- PHP5中GD庫生成圖形驗證碼(有漢字)
- php仿QQ驗證碼的實例分析
- php 驗證碼(傾斜,正弦干擾線,黏貼,旋轉(zhuǎn))
- php ci框架驗證碼實例分析
- PHP實現(xiàn)的封裝驗證碼類詳解
- 探討如何在php168_cms中提取驗證碼
- 如何用php生成扭曲及旋轉(zhuǎn)的驗證碼圖片
- php實現(xiàn)加減法驗證碼代碼
相關文章
laravel與thinkphp之間的區(qū)別與優(yōu)缺點
這篇文章主要介紹了laravel與thinkphp之間的區(qū)別與優(yōu)缺點,從多個方面對比,有正好使用這兩個框架的同學可以研究下2021-03-03PHP時間戳和日期相互轉(zhuǎn)換操作實例小結(jié)
這篇文章主要介紹了PHP時間戳和日期相互轉(zhuǎn)換操作,結(jié)合實例形式總結(jié)分析了php常見的各種日期與時間戳轉(zhuǎn)換操作使用技巧與注意事項,需要的朋友可以參考下2018-12-12php循環(huán)語句 for()與foreach()用法區(qū)別介紹
下面我用兩個實例來介紹一下關于在php中foreach與for語句用法區(qū)別介紹,有需要的朋友可參考一下2012-09-09php mb_substr()函數(shù)截取中文字符串應用示例
substr()函數(shù)用來截取字符串,但是對于中文字符會出現(xiàn)問題,而mb_substr()和mb_strcut這兩個函數(shù)可以,下面為大家介紹其具體用法2014-07-07joomla jce editor 解決上傳中文名文件失敗問題
要么上傳失敗,要么傳上去了中文名不能被web訪問,研究了下JCE的源碼,改掉保存文件名的方式,使用純數(shù)字來作為文件名,具體修改如下,遇到類型情況的朋友可以參考下哈2013-06-06