好看的php验证码,一漂亮的PHP图片验证码实例
一、顯示效果
二、代碼如下
代碼如下:/*
*? @Author fy
*/
$imgwidth?=100; //圖片寬度
$imgheight?=40; //圖片高度
$codelen?=4; //驗(yàn)證碼長(zhǎng)度
$fontsize?=20; //字體大小
$charset = 'abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789';
$font = 'Fonts/segoesc.ttf';
$im=imagecreatetruecolor($imgwidth,$imgheight);
$while=imageColorAllocate($im,255,255,255);
imagefill($im,0,0,$while); //填充圖像
//取得字符串
$authstr='';
$_len = strlen($charset)-1;
for ($i=0;$i
$authstr .= $charset[mt_rand(0,$_len)];
}
session_start();
$_SESSION['scode']=strtolower($authstr);//全部轉(zhuǎn)為小寫(xiě),主要是為了不區(qū)分大小寫(xiě)
//隨機(jī)畫(huà)點(diǎn),已經(jīng)改為劃星星了
for ($i=0;$i
$randcolor=imageColorallocate($im,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
imagestring($im,mt_rand(1,5), mt_rand(0,$imgwidth),mt_rand(0,$imgheight), '*',$randcolor);
//imagesetpixel($im,mt_rand(0,$imgwidth),mt_rand(0,$imgheight),$randcolor);
}
//隨機(jī)畫(huà)線,線條數(shù)量=字符數(shù)量(隨便)
for($i=0;$i
{
$randcolor=imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imageline($im,0,mt_rand(0,$imgheight),$imgwidth,mt_rand(0,$imgheight),$randcolor);
}
$_x=intval($imgwidth/$codelen); //計(jì)算字符距離
$_y=intval($imgheight*0.7); //字符顯示在圖片70%的位置
for($i=0;$i
$randcolor=imagecolorallocate($im,mt_rand(0,150),mt_rand(0,150),mt_rand(0,150));
//imagestring($im,5,$j,5,$imgstr[$i],$color3);
// imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )
imagettftext($im,$fontsize,mt_rand(-30,30),$i*$_x+3,$_y,$randcolor,$font,$authstr[$i]);
}
//生成圖像
header("content-type:image/PNG");
imagePNG($im);
imageDestroy($im);
本條技術(shù)文章來(lái)源于互聯(lián)網(wǎng),如果無(wú)意侵犯您的權(quán)益請(qǐng)點(diǎn)擊此處反饋版權(quán)投訴
本文系統(tǒng)來(lái)源:php中文網(wǎng)
TAG標(biāo)簽:腳本
總結(jié)
以上是生活随笔為你收集整理的好看的php验证码,一漂亮的PHP图片验证码实例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 学习笔记之Bitbucket
- 下一篇: 动态规划算法php,php算法学习之动态