php验证码验证不成功,PHP验证码图片 生成不成功

//验证码

public function verifAction($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;//字体大小

$fontcolor=imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,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['capatch']=strtolower($capatch);

file_put_contents('a.txt', $_SESSION['capatch']);

imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);

}

//干扰点

if($interference == true){

for($i=0;$i<100;$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;$i<2;$i++){

$linecolor=imagecolorallocate($image,rand(100,200),rand(100,200),rand(100,200));

imageline($image,rand(1,99),rand(1,29),rand(1,99),rand(1,29),$linecolor);

}

}

$_SESSION['authcode']=$capatch;

header('content-type:image/png');

imagepng($image); // 输出图片

imagedestroy($image);//销毁图片

}

317cb1422bf3965d0668a27a1ae3acb4.png

这段代码在框架之外生成验证码是正常的,但是一旦放到代码里面就不正常了。我用url直达这个函数,得到的永远是一片没有验证码的黑色背景?请教各位大神,问题可能出在哪了?

我用的是zend-framework框架.

-------------------分割线---------

public function verifAction(){

header("Content-type:image/png");

$a = imagecreate(100,100);

imagecolorallocate($a,255,0,255);

imagepng($a);

imagedestroy($a);

exit();

}

我刚刚再试发现,只创建一块画面,画布也输不出来。这是哪里的问题?

换了个浏览器是这样的。

ad4303ac1b453cdf015b15b3c6180417.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值