在getverify.php中调用时,只显示干扰项不显示数字,在image.func.php中就正常显示内容和干扰项,为什么?
<?php require_once 'D:\www\shopimooc\lib\image.func.php'; verifyImage(1,4,50,5);
这样写的代码不能显示画布里面的内容 干扰项都能显示为什么,有遇到过的么?
<?php require_once 'D:\www\shopimooc\lib\image.func.php'; verifyImage(1,4,50,5);
这样写的代码不能显示画布里面的内容 干扰项都能显示为什么,有遇到过的么?
2017-07-31
<?php
require_once 'string.func.php';
function verifyImage($type=1,$length=4,$pixel=0,$line=0){
session_start();
$width=80;
$height=30;
$image=imagecreatetruecolor($width,$height);
$white=imagecolorallocate($image,255,255,255);
$black=imagecolorallocate($image,0,0,0);
//用填充矩形填充画布
imagefilledrectangle($image,1,1,$width-2,$height-2,$white);
$chars=bulidRandomString($type,$length);
$sess_name="verify";
$_SESSION[$sess_name]=$chars;
$fontfiles=array("SIMYOU.TTF");
for($i=0;$i<$length;$i++){
$size=mt_rand(14,18);
$angle=mt_rand(-15,15);
$x=5+$i*$size;
$y=mt_rand(20,26);
$color=imagecolorallocate($image,mt_rand(50,90),mt_rand(80,200),mt_rand(90,180));
$fontfile = "../fonts/" . $fontfiles [mt_rand ( 0, count ( $fontfiles ) - 1 )];
$text=substr($chars,$i,1);
imagettftext($image,$size,$angle,$x,$y,$color,$fontfile,$text);
}
//加验证码干扰元素
//加点
for($i=0;$i<$pixel;$i++){
imagesetpixel($image,mt_rand(0,$width-1),mt_rand(0,$height-1),$black);
}
//加线
for($i=0;$i<$line;$i++){
$color=imagecolorallocate($image,mt_rand(50,90),mt_rand(80,200),mt_rand(90,180));
imageline($image,mt_rand(0,$width-1),mt_rand(0,$height-1),mt_rand(0,$width-1),mt_rand(0,$height-1),$color);
}
ob_clean(); //ob_clean这个函数的作用就是用来丢弃输出缓冲区中的内容,如果你的网站有许多生成的图片类文件,那么想要访问正确,就要经常清除缓冲区。
header("content-type:image/gif");
imagegif($image);
imagedestroy($image);
}
举报