我不喜欢因为一个简单的验证码就大费周章,甚至连font字库文件都有,常常发现有的程序不过才两兆多点,而字库占去了至少1.5兆,唉!搞不懂那位是怎么想的,简直就是太有创意了
我不喜欢,所以自己写了一个简单而又漂亮的高效的.
$work=AddsLashes($_REQUEST["work"]);
Switch ($work){
Case "cod":
_cod();
Break;
Default:
_main();
Break;
}
//------------------------------------------------*
Function _main(){
Session_start();
Echo "<img src='?work=cod' width='68' height='20' onclick=\"this.src='?work=cod&'+Math.random(10)\" style='cursor:pointer;'>".$_SESSION['cod'];
}
//------------------------------------------------*
Function _cod(){
OB_start();
OB_clean();
For($i=0;$i<4;$i++){//dechex将10进制转为16进制
$num .= Dechex(Mt_Rand(1,15));
}
Session_start();$_SESSION['cod']=$num;
$img=Imagecreatetruecolor(60,20);//建立画布
$bgc=Imagecolorallocate($img,255,255,255);//创建图片背景颜色
Imagefill($img,0,0,$bgc);
For($i=0;$i<Mt_Rand(0,5);$i++){//添加随机线条
$linc=Imagecolorallocate($img,200,200,Mt_Rand(0,255));
Imageline($img,Mt_Rand(5,55),Mt_Rand(5,15),Mt_Rand(5,55),Mt_Rand(5,15),$linc);
}
For($i=0;$i<2;$i++){
$col=Imagecolorallocate($img,Mt_Rand(10,60),Mt_Rand(100,150),Mt_Rand(0,200));//字体颜色
Imagestring($img,6,(10+$i*9),(2+$i*2),($num[$i]."-".$num[($i+2)]),$col);//写入文字
}
Header('content-type:Image/png');
Imagepng($img);
Die();
}
?>
我不喜欢,所以自己写了一个简单而又漂亮的高效的.
//如果要轉載本文請注明出處,免的出現版權紛爭,我不喜歡看到那種轉載了我的作品卻不注明出處的人 Seven{See7di#Gmail.com}
<?php$work=AddsLashes($_REQUEST["work"]);
Switch ($work){
Case "cod":
_cod();
Break;
Default:
_main();
Break;
}
//------------------------------------------------*
Function _main(){
Session_start();
Echo "<img src='?work=cod' width='68' height='20' onclick=\"this.src='?work=cod&'+Math.random(10)\" style='cursor:pointer;'>".$_SESSION['cod'];
}
//------------------------------------------------*
Function _cod(){
OB_start();
OB_clean();
For($i=0;$i<4;$i++){//dechex将10进制转为16进制
$num .= Dechex(Mt_Rand(1,15));
}
Session_start();$_SESSION['cod']=$num;
$img=Imagecreatetruecolor(60,20);//建立画布
$bgc=Imagecolorallocate($img,255,255,255);//创建图片背景颜色
Imagefill($img,0,0,$bgc);
For($i=0;$i<Mt_Rand(0,5);$i++){//添加随机线条
$linc=Imagecolorallocate($img,200,200,Mt_Rand(0,255));
Imageline($img,Mt_Rand(5,55),Mt_Rand(5,15),Mt_Rand(5,55),Mt_Rand(5,15),$linc);
}
For($i=0;$i<2;$i++){
$col=Imagecolorallocate($img,Mt_Rand(10,60),Mt_Rand(100,150),Mt_Rand(0,200));//字体颜色
Imagestring($img,6,(10+$i*9),(2+$i*2),($num[$i]."-".$num[($i+2)]),$col);//写入文字
}
Header('content-type:Image/png');
Imagepng($img);
Die();
}
?>