php captcha 不显示,关于Captcha.php显示的问题

苦思不得向大佬求教:

1.运行php -S的界面是不是不能输出var_dump,如果要调试该怎么做?

2.我的Captcha.php不显示图像也不报错。该如何解决呢?

44445777d7e592198e4d8cc55865eb48.png

class Captcha{

private $codeNum;

private $width;

private $height;

private $img;

private $lineFlag;

private $piexFlag;

private $fontSize;

private $code;

private $string;

private $font;

function __construct($codeNum=4,$height=50,$width=150,$fontSize=20,$lineFlag=true,$piexFlag=true){

$this->string ="qwertyuiopasdfghjklzxcvbnm";

$this->codeNum =$codeNum;

$this->width =$width;

$this->height=$height;

$this->lineFlag =$lineFlag;

$this->piexFlag =$piexFlag;

$this->font =dirname(__FILE__).'/fonts/consola.ttf';

$this->fontSize =$fontSize;

}

public function createImage(){

var_dump($this->width);

var_dump($this->height);

$this->img=imagecreate($this->width,$this->height);

imagecolorallocate($this->img, mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));

}

public function createCode(){

$strlen=strlen($this->string)-1;

for($i=0;$icodeNum;$i++){

$this->code .=$this->string[mt_rand(0,$strlen)];

}

$_SESSION['code']=$this->code;

var_dump($this->code);

$diff=$this->width/$this->codeNum;

for($i=0;$icodeNum;$i++){

$txtColor=imagecolorallocate($this->img, mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));

imagettftext($this->img,$this->fontSize,mt_rand(-30,30),$diff*$i+mt_rand(3,8),mt_rand(20,$this->height-10),$txtColor,$this->font,$this->code[$i]);

}

}

public function createLines(){

for($i=0;$i<4;$i++){

$color=imagecolorallocate($this->img,mt_rand(0,155),mt_rand(0,155),mt_rand(0,155));

imageline($this->img,mt_rand(0,$this->width),mt_rand(0,$this->height),mt_rand(0,$this->width),mt_rand(0,$this->height),$color);

}

}

public function createPiex(){

for($i=0;$i<100;$i++){

$color=imagecolorallocate($this->img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));

imagesetpixel($this->img,mt_rand(0,$this->width),mt_rand(0,$this->height),$color);

}

}

public function show(){

$this->createImage();

$this->createCode();

if($this->lineFlag){

$this->createLines();

}

if($this->piexFlag){

$this->createPiex();

}

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

imagepng($this->img);

imagedestroy($this->img);

}

public function getCode(){

return $this->code;

}

}

session_start();

$captcha=new Captcha();

$captcha->show();

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值