php生成验证码的步骤,PHP验证码
//认证码
publicfunctionverifaction ($ num=3,$interference=true ) {
$ image=imagecreate (100,30 ); //制作画布
$ bgcolor=imagecolorallocate ($ image,255,255,255 ); //画布背景色
imagefill($image,0,0,$bgcolor ); //填充背景输出$num位认证码
$capatch=' ';
for($I=0; $i
$fontsize=14; //字体大小
$ font color=imagecolorallocate ($ image,rand )、rand )、120 )、rand )、120 ) ); //字体颜色
$ date=' qwertyupasdghjkzxcvbnmqwertyupasdfghjkzxcvbnm ';
$fontcontent=substr($date,rand(0),strlen ) $date(-1 ),1 );
$capatch.=$fontcontent;
$ x=$ I * 100/$ num (rand (5,10 );
美元y=rand (5,10 ); //生成认证码
$ _ session [ ' ca patch ' ]=strtolower $ ca patch;
file_put_contents('a.txt ',$_SESSION['capatch'] );
imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor );
}
//干涉点
if($interference==true ) {
for($I=0; $i100; $i ) {
$ pointcolor=imagecolorallocate $ image,rand (50,200 ),rand (50,200 ),rand (50,200 );
imagesetpixel($image,rand ) 1,99 ),rand ) 1,29 ),$pointcolor ); (//干涉线
for($I=0; $i2; $i ) {
$ line color=imagecolorallocate ($ image,rand ) 100,200 )、rand (100,200 )、rand (100,200 ) );
imageline($image,rand ) 1,99 )、rand ) 1,29 )、rand ) 1,99 )、rand )、$linecolor );
}
}
$_SESSION['authcode']=$capatch;
头(content-type : image/png );
imagepng($image; //输出图像
imagedestroy($image; //销毁照片
}
该代码在框架外生成验证码是正常的,但放在代码中就不正常了。 我用url直奔这个函数,得到的是永远没有验证码的黑色背景吗? 各位,问题可能在哪里?
我使用的是zend-framework框架。
------分割线------分割线
公共函数函数(
头(content-type : image/png );
$ a=imagecreate (100,100 );
imagecolorallocate($a,255,0,255 );
imagepng($a;
imagedestroy($a;
exit (;
}
我再试了一次,发现只做一张画面,画布也不会输。 这是哪里的问题?
换了浏览器是这样的。