欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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)論