类别:PHP问题 / 日期:2019-12-02 / 浏览:91 / 评论:0

处理方法:
1、搜检PHP是不是已装置GD扩大,而且开启状况; (引荐进修:PHP视频教程)
2、utf-8 BOM头缘由。用Editplus、ultraedit,删除即可。(https://blog.csdn.net/oscar999/article/details/6280006)
3、输出缓冲区中的缓存题目。输出前,运用ob_clean函数处理。
4、输出前,不能涌现echo、print_r、var_dump等打印,解释或删除处理。
处理题目以后的代码:
<?php $w = 80; //设置图片宽和高 $h = 26; $str = Array(); //用来存储随机码 $string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";//随机遴选个中4个字符,也能够挑选更多,注重轮回的时刻加上,宽度恰当调解 for($i = 0;$i < 4;$i++){ $str[$i] = $string[rand(0,35)]; $vcode .= $str[$i]; } session_start(); //启用超全局变量session $_SESSION["vcode"] = $vcode; $im = imagecreatetruecolor($w,$h); $white = imagecolorallocate($im,255,255,255); //第一次挪用设置背景色 $black = imagecolorallocate($im,0,0,0); //边框色彩 imagefilledrectangle($im,0,0,$w,$h,$white); //画一矩形添补 imagerectangle($im,0,0,$w-1,$h-1,$black); //画一矩形框 //生成雪花背景 for($i = 1;$i < 200;$i++){ $x = mt_rand(1,$w-9); $y = mt_rand(1,$h-9); $color = imagecolorallocate($im,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255)); imagechar($im,1,$x,$y,"*",$color); } //将验证码写入图案 for($i = 0;$i < count($str);$i++){ $x = 13 + $i * ($w - 15)/4; $y = mt_rand(3,$h / 3); $color = imagecolorallocate($im,mt_rand(0,225),mt_rand(0,150),mt_rand(0,225)); imagechar($im,5,$x,$y,$str[$i],$color); } ob_clean();//本来的顺序没有这一栏 header("Content-type:image/jpeg"); //以jpeg花样输出,注重上面不能输出任何字符,不然失足 imagejpeg($im); imagedestroy($im); ?>
显现效果以下:
以上就是php验证码不显现处理方法的细致内容,更多请关注ki4网别的相干文章!
发表评论 / 取消回复