最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP實(shí)現(xiàn)變色驗(yàn)證碼實(shí)例

 更新時(shí)間:2014年01月06日 17:51:16   投稿:whsnow  
驗(yàn)證碼想必大家都有見到過吧,在本文為大家介紹下PHP如何實(shí)現(xiàn)變色驗(yàn)證碼,感興趣的朋友可以參考下

復(fù)制代碼 代碼如下:

<?php
header("Content-type: image/png,charset='utf-8'");
$im = imagecreatetruecolor(400, 30);
//白色
$white = imagecolorallocate($im, 255, 255, 255);
//紅色
$red = imagecolorallocate($im, 255, 0, 0);
//黑色
$black=imagecolorallocate($im, 0, 0, 0);
//綠色
$green=imagecolorallocate($im, 0, 255, 0);
//藍(lán)色
$blue=imagecolorallocate($im, 0, 0, 255);
$color_arr=array($green,$blue,$red);
$color=array_rand($color_arr);
$textlen=iconv_strlen($text,'utf-8');//計(jì)算字符串長度
//隨機(jī)截取兩個(gè)字符,變色顯示
$p1=rand(1,$textlen)-1;
while(($p2=rand(1,$textlen)-1)==$p1);
$w1=iconv_substr($text,$p1,1,'utf-8');
$w2=iconv_substr($text,$p1,1,'utf-8');
//字體文件 (PS:T不錯(cuò)的php Q扣峮:276167802,驗(yàn)證:csl)
$font = 'simkai.ttf';
imagefilledrectangle($im, 0, 0, 399, 29, $white);
for($i=0;$i<$textlen;$i++)
{
if($i==$p1||$i==$p2)
{
imagettftext($im, 15, 0, 20*($i-1)+20, 20, $color_arr[$color], $font, iconv_substr($text,$i,1,'utf-8'));
}
else
{
imagettftext($im, 15, 0, 20*($i-1)+20, 20, $black, $font, iconv_substr($text,$i,1,'utf-8'));
}
}
imagepng($im);
imagedestroy($im);
?>

驗(yàn)證碼中的字符并不是同一種顏色,讓用戶輸入指定顏色的驗(yàn)證碼,這樣安全性會(huì)更好的。

相關(guān)文章

最新評(píng)論

盐城市| 西乌珠穆沁旗| 广河县| 手游| 榕江县| 莲花县| 家居| 虎林市| 池州市| 乌鲁木齐市| 陵川县| 济阳县| 施甸县| 平武县| 天等县| 哈尔滨市| 江安县| 小金县| 瑞金市| 翁源县| 凉城县| 贵定县| 阿尔山市| 靖安县| 凉城县| 扬中市| 商南县| 额尔古纳市| 什邡市| 平潭县| 凤山市| 察雅县| 义马市| 临洮县| 黔南| 平南县| 砚山县| 来安县| 临沧市| 西藏| 太仆寺旗|