PHP自定義大小驗證碼的方法詳解
更新時間:2013年06月07日 11:15:56 作者:
本篇文章是對PHP自定義大小驗證碼進行了詳細(xì)的分析介紹,需要的朋友參考下
復(fù)制代碼 代碼如下:
<?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)加減法驗證碼代碼
相關(guān)文章
PHP PDO函數(shù)庫(PDO Functions)
PDO是一個“數(shù)據(jù)庫訪問抽象層”,作用是統(tǒng)一各種數(shù)據(jù)庫的訪問接口,與mysql和mysqli的函數(shù)庫相比,PDO讓跨數(shù)據(jù)庫的使用更具有親和力.2009-07-07
php-redis中的sort排序函數(shù)總結(jié)
這篇文章主要介紹了php-redis中的sort排序函數(shù)總結(jié),本文講解了了按字母排序、排序取部分?jǐn)?shù)據(jù)、使用外部key進行排序等排序方法,同時給出代碼實例,需要的朋友可以參考下2015-07-07
php中substr()函數(shù)參數(shù)說明及用法實例
這篇文章主要介紹了php中substr()函數(shù)參數(shù)說明及用法,以實例形式深入分析了substr()函數(shù)中的各個參數(shù)的含義,并舉例說明了其對應(yīng)的用法,需要的朋友可以參考下2014-11-11
PHP多維數(shù)組遍歷方法(2種實現(xiàn)方法)
這篇文章主要介紹了PHP多維數(shù)組遍歷方法,實例分析了2種多維數(shù)組的遍歷技巧,包括簡單的foreach遍歷與遞歸操作遍歷實現(xiàn)方法,需要的朋友可以參考下2015-12-12
PHP實現(xiàn)把數(shù)字ID轉(zhuǎn)字母ID
以下是對使用PHP把數(shù)字ID轉(zhuǎn)字母ID的實現(xiàn)代碼進行了詳細(xì)的分析介紹,需要的朋友可以過來參考下2013-08-08
php $_SERVER windows系統(tǒng)與linux系統(tǒng)下的區(qū)別說明
本篇文章主要是對php $_SERVER windows系統(tǒng)與linux系統(tǒng)下的區(qū)別進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-02-02

