以前的服务器验证码可以显示,换了台就是显示不了,但是服务器上其他网站的验证码可以显示,本地测试也能显示。。
测式地址http://guwen.ccwlsh.net/?do=user&act=reg
直接输验证码地址http://guwen.ccwlsh.net/?do=yzm&act=yzm
测式地址http://guwen.ccwlsh.net/?do=user&act=reg
直接输验证码地址http://guwen.ccwlsh.net/?do=yzm&act=yzm
Failed to load resource: the server responded with a status of 404 (Not Found) pwdStrong.js
<?php
if(!defined('IN_ROOT')) {
exit('Access Denied');
}
class CCheckCodeFile{
private $mCheckCodeNum = 4;//验证码位数
private $mCheckCode = ''; //产生的验证码
private $mCheckImage = ''; //验证码的图片
private $mDisturbColor = '';//干扰像素
private $mCheckImageWidth = '50'; //验证码的图片宽度
private $mCheckImageHeight = '20';//验证码的图片高度
/**
*
* @brief 输出头
*
*/
private function OutFileHeader(){
header("Content-type:image/png");
}
/**
*
* @brief 产生验证码
*
*/
private function CreateCheckCode(){
$srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
$strs = "";
for($i=0;$i<4;$i++){
$strs.=$srcstr[mt_rand(0,35)];
}
$strs = strtoupper($strs);
$this->mCheckCode = $strs;
$_SESSION['code']=$this->mCheckCode;
//return $_SESSION['yzm'];
} /**
*
* @brief 产生验证码图片
*
*/
private function CreateImage(){
$this->mCheckImage = @imagecreate ($this->mCheckImageWidth,$this->mCheckImageHeight);
imagecolorallocate ($this->mCheckImage, 255, 255, 255);
return $this->mCheckImage;
} /**
*
* @brief 设置图片的干扰像素
*
*/
private function SetDisturbColor(){
for ($i=0;$i<=128;$i++){
$this->mDisturbColor = imagecolorallocate ($this->mCheckImage, rand(0,255), rand(0,255), rand(0,255));
imagesetpixel($this->mCheckImage,rand(2,128),rand(2,38),$this->mDisturbColor);
}
} /**
*
* @brief 设置验证码图片的大小
*
* @param $width 宽
*
* @param $height 高
*
*/
public function SetCheckImageWH($width,$height){
if($width==''||$height=='')return false;
$this->mCheckImageWidth = $width;
$this->mCheckImageHeight = $height;
return true;
} /**
*
* @brief 在验证码图片上逐个画上验证码
*
*/
private function WriteCheckCodeToImage(){
for ($i=0;$i<=$this->mCheckCodeNum;$i++){
$bg_color = imagecolorallocate ($this->mCheckImage, rand(0,255), rand(0,128), rand(0,255));
$x = floor($this->mCheckImageWidth/$this->mCheckCodeNum)*$i;
$y = rand(0,$this->mCheckImageHeight-15);
imagechar ($this->mCheckImage, 5, $x, $y, $this->mCheckCode[$i], $bg_color);
}
} /**
*
* @brief 输出验证码图片
*
*/
public function OutCheckImage(){
$this ->OutFileHeader();
$this ->CreateCheckCode();
$this ->CreateImage();
$this ->SetDisturbColor();
$this ->WriteCheckCodeToImage();
imagepng($this->mCheckImage);
imagedestroy($this->mCheckImage);
}
}?>
$this->mCheckImage = @imagecreate ($this->mCheckImageWidth,$this->mCheckImageHeight); //去掉@符号看会不会报错
imagecolorallocate ($this->mCheckImage, 255, 255, 255);
return $this->mCheckImage;
}
Notice: Uninitialized string offset: 4 in D:\mydir\test.php on line 8787行在我这里是:
imagechar ($this->mCheckImage, 5, $x, $y, $this->mCheckCode[$i], $bg_color);
$bg_color = imagecolorallocate ($this->mCheckImage, rand(0,255), rand(0,128), rand(0,255));
$x = floor($this->mCheckImageWidth/$this->mCheckCodeNum)*$i;
$y = rand(0,$this->mCheckImageHeight-15);//echo $this->mCheckCode[$i];exit;
imagechar ($this->mCheckImage, 5, $x, $y, $this->mCheckCode[$i], $bg_color);
}
赋值你的类定义代码到 ANSI 编码的文件中
然后
$p = new CCheckCodeFile;
$p->SetCheckImageWH(100, 60);
$p->OutCheckImage();正常产生了图片,就这样简单。
不存在程序代码问题!十六进制的 efbbbf 就是 utf-8 编码文件的 BOM 头,这是众人皆知的考虑到
直接输验证码地址 http://guwen.ccwlsh.net/?do=yzm&act=yzm
是单入口模式,你需要检查路由到的每一个文件(包括配置文件)是否没有去掉 BOM 头