Bing Yee程序人生

关注互联网产品技术学习,应用开发~

帝国CMS 验证码"因其本身有错而无法显示" 解决方法

2012/2/28 18:25:17 类别:网络编程
摘要:最近应客户要求,用帝国CMS 套一个门户站,搞了几天,对整个系统有了个大概的了解,感觉还是很强大的,有很多程序设计上的可取之处. 对了说重点,关于验证码不显示(直接访问提示"因其本身有错无法显示")


最近应客户要求,用帝国CMS 套一个2012利率站,搞了几天,对整个系统有了个大概的了解,感觉还是很强大的,有很多程序设计上的可取之处. 对了说重点,关于验证码不显示(直接访问提示"因其本身有错无法显示")

焦急中百度一下,有很多原因,有因为GD库不支持,有因为路径不对....

尝试后,发现都没发解决我的,继续搜索

最终看到有人在Header("Content-type: image/PNG");这句代码前使用ob_clean();清除输出,结果一试之下果然成功。

下面贴下帝国的验证码显示代码 一句代码的强大 希望 帝国也跟进

//显示验证码
function ShowKey($v){
 $vname=ecmsReturnKeyVarname($v);
 $key=strtolower(domake_password(4));
 ecmsSetShowKey($vname,$key);
 ob_clean();
 //是否支持gd库
 if(function_exists("imagejpeg")) 
 {
  header ("Content-type: image/jpeg");
  $img=imagecreate(47,20);
  $colorr=ReturnShowKeyColor($img);
  $bgcolor=$colorr['bgcolor'];
  $fontcolor=$colorr['fontcolor'];
  $distcolor=$colorr['distcolor'];
  imagefill($img,0,0,$bgcolor);
  imagestring($img,5,6,3,$key,$fontcolor);
  for($i=0;$i<90;$i++) //加入干扰象素
  {
   imagesetpixel($img,rand()%70,rand()%30,$distcolor);
  }
  imagejpeg($img);
  imagedestroy($img);
 }
 elseif (function_exists("imagepng"))
 {
  header ("Content-type: image/png");
  $img=imagecreate(47,20);
  $colorr=ReturnShowKeyColor($img);
  $bgcolor=$colorr['bgcolor'];
  $fontcolor=$colorr['fontcolor'];
  $distcolor=$colorr['distcolor'];
  imagefill($img,0,0,$bgcolor);
  imagestring($img,5,6,3,$key,$fontcolor);
  for($i=0;$i<90;$i++) //加入干扰象素
  {
   imagesetpixel($img,rand()%70,rand()%30,$distcolor);
  }
  imagepng($img);
  imagedestroy($img);
 }
 elseif (function_exists("imagegif")) 
 {
  header("Content-type: image/gif");
  $img=imagecreate(47,20);
  $colorr=ReturnShowKeyColor($img);
  $bgcolor=$colorr['bgcolor'];
  $fontcolor=$colorr['fontcolor'];
  $distcolor=$colorr['distcolor'];
  imagefill($img,0,0,$bgcolor);
  imagestring($img,5,6,3,$key,$fontcolor);
  for($i=0;$i<90;$i++) //加入干扰象素
  {
   imagesetpixel($img,rand()%70,rand()%30,$distcolor);
  }
  imagegif($img);
  imagedestroy($img);
 }
 elseif (function_exists("imagewbmp")) 
 {
  header ("Content-type: image/vnd.wap.wbmp");
  $img=imagecreate(47,20);
  $colorr=ReturnShowKeyColor($img);
  $bgcolor=$colorr['bgcolor'];
  $fontcolor=$colorr['fontcolor'];
  $distcolor=$colorr['distcolor'];
  imagefill($img,0,0,$bgcolor);
  imagestring($img,5,6,3,$key,$fontcolor);
  for($i=0;$i<90;$i++) //加入干扰象素
  {
   imagesetpixel($img,rand()%70,rand()%30,$distcolor);
  }
  imagewbmp($img);
  imagedestroy($img);
 }
 else
 {
  ecmsSetShowKey($vname,'ecms');
  echo ReadFiletext("../data/images/ecms.jpg");
 }
}

关键的一句 ob_clean(); 清除输出 谨记备查

3122次阅读  标签:验证码,帝国CMS,ECMS
下一篇:帝国CMS 首页调用showtags 无法显示标签
上一篇:Android在Windows中开发环境的搭建

共7条评论

ヴィクトリアシークレット水着激安(1楼)-2014/3/28 5:00:51
审核中

abhtjrqdttx(2楼)-2015/12/28 3:02:34
审核中

chaba(3楼)-2016/2/3 16:09:50
审核中

home(4楼)-2016/11/4 8:56:36
审核中

发表评论

文章分类


友情链接