您好,欢迎访问一九零五行业门户网

php验证码和不能正常显示解决办法

php验证码和不能正常显示解决方法
效果如图:
?
文件都放到了同一文件夹下。
?
createimage.class.php
width=$width; $this->height=$height; $this->codenum=$codenum; } function outimg() { //输出头 $this->outfileheader(); //产生验证码 $this->createcode(); //产生图片 $this->createimage(); //设置干扰像素 $this->setdisturbcolor(); //往图片上写验证码 $this->writecheckcodetoimage(); imagepng($this->checkimage); imagedestroy($this->checkimage); } private function outfileheader() { header ('content-type: image/png'); } private function createcode() { $this->checkcode = strtoupper(substr(md5(rand()),0,$this->codenum)); } private function createimage() { $this->checkimage = @imagecreate($this->width,$this->height); $back = imagecolorallocate($this->checkimage,255,255,255); $border = imagecolorallocate($this->checkimage,0,0,0); imagefilledrectangle($this->checkimage,0,0,$this->width - 1,$this->height - 1,$back); // 白色底 imagerectangle($this->checkimage,0,0,$this->width - 1,$this->height - 1,$border); // 黑色边框 } private function setdisturbcolor() { for ($i=0;$idisturbcolor = imagecolorallocate($this->checkimage, rand(0,255), rand(0,255), rand(0,255)); imagesetpixel($this->checkimage,rand(2,128),rand(2,38),$this->disturbcolor); } } private function writecheckcodetoimage() { for ($i=0;$icodenum;$i++) { $bg_color = imagecolorallocate ($this->checkimage, rand(0,255), rand(0,128), rand(0,255)); $x = floor($this->width/$this->codenum)*$i; $y = rand(0,$this->height-15); imagechar ($this->checkimage, rand(5,8), $x, $y, $this->checkcode[$i], $bg_color); } } function __destruct() { unset($this->width,$this->height,$this->codenum); }}
?
checks.php
?
?
index.php
?
rand函数的应用
用户名
密码
验证码

?
************************************容易出现的问题*************
?
?
?
1.未开启php_gd2.dll? 去php.ini将其前面的“ ;”去掉
2.上面的checks.php中 3.字符编码改为统一的
4.最容易忽略的一点:
? 你本机上的环境是将报错提示全部打开的,所以在输出时有系统的未定义提示信息也跟着一起输出了,这样生成的图片肯定就不正常了,方法有两,在validationcode.php和checks.php文件开头加上ini_set('display_errors',?'off');就ok了
?
?
?
**********************************************************
?
其它类似信息

推荐信息