验证码显示x 我的电脑打开别人的网站是可以显示验证码的,就是我自己用php做的网站验证码显示x,不知道怎么解决?我是用wamp 5运行的,请各位大侠帮帮忙啊?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 估计在验证码类中少了这header("Content-Type:image/png"); 一定不能有META 语句,因为输出的是图象,所以不能有除图象地址之外的任何输出,包含空格 我之前也是用这个验证码的啊!都没有问题,只是后来又重新安啦一次wamp5就变x啦,这个应该怎么做啊? 是不是那个wamp5里面有个可以改的?我怕记得之前也是现实x,我就不知道怎么改啦一下,好啦,现在又重新按一次wamp5就又不行啦,就不知道怎么改啦!会的帮个忙啊?谢谢! <? //随机字符串种子,可以换成字母或其他英文字符 $glbVerifySeed = "AbcDefGhijkL1234567890mnOpqRstuvwxYz"; main(); function main() { session_start(); $verifyCode = getRandomCode(); $_SESSION["verifyCode"] = $verifyCode; $imgWidth = $_REQUEST["width"]; $imgHeight = $_REQUEST["height"]; $imgFont = $_REQUEST["font"]; if($imgWidth == "") $imgWidth = 50; if($imgHeight == "") $imgHeight = 18; if($imgFont == "") $imgFont = 6; doOutputImg($verifyCode, $imgWidth, $imgHeight, $imgFont); } //获取随机数字字符串 function getRandomCode($length=4) { global $glbVerifySeed; $bgnIdx = 0; $endIdx = strlen($glbVerifySeed)-1; $code = ""; for($i=0; $i<$length; $i++) { $curPos = rand($bgnIdx, $endIdx); $code .= substr($glbVerifySeed, $curPos, 1); } return $code; } //输出校验码图像 function doOutputImg($string, $imgWidth, $imgHeight, $imgFont, $imgFgColorArr=array(0,0,0), $imgBgColorArr=array(255,255,255)) { $image = imagecreatetruecolor($imgWidth, $imgHeight); //用白色背景加黑色边框画个方框 $backColor = imagecolorallocate($image, 255, 255, 255); $borderColor = imagecolorallocate($image, 255, 255, 255); imagefilledrectangle($image, 0, 0, $imgWidth - 1, $imgHeight - 1, $backColor); imagerectangle($image, 0, 0, $imgWidth - 1, $imgHeight - 1, $borderColor); $imgFgColor = imagecolorallocate ($image, $imgFgColorArr[0], $imgFgColorArr[1], $imgFgColorArr[2]); doDrawStr($image, $string, $imgFgColor, $imgFont); doPollute($image, 64); header('Content-type: image/png'); imagepng($image); imagedestroy($image); } //画出校验码 function doDrawStr($image, $string, $color, $imgFont) { $imgWidth = imagesx($image); $imgHeight = imagesy($image); $count = strlen($string); $xpace = ($imgWidth/$count); $x = ($xpace-6)/2; $y = ($imgHeight/2-8); for ($p = 0; $p<$count; $p ++) { $xoff = rand(-2, +2); $yoff = rand(-2, +2); $curChar = substr($string, $p, 1); imagestring($image, $imgFont, $x+$xoff, $y+$yoff, $curChar, $color); $x += $xpace; } return 0; } //画出一些杂点 function doPollute($image, $times) { $imgWidth = imagesx($image); $imgHeight = imagesy($image); for($j=0; $j<$times; $j++) { $x = rand(0, $imgWidth); $y = rand(0, $imgHeight); $color = imagecolorallocate($image, rand(0,255), rand(0,255), rand(0,255)); imagesetpixel($image, $x, $y, $color); } }?> 我显示正常哦~你把文件格式改为utf8无bom头 是配置文件中php.ini中设置不对,将图形库的那个注释去掉就可以 php下载文件问题,求xdjm们帮忙,贴里面详细描述了问题,谢谢! CodeIgniter加载session类 提示错误 怎么解决 QQ一键登录 乱码问题 fwrite问题 如何制作服务器套件? 高薪聘请网络工程师(>4800rmb/月): [求助] 上传文件无响应 [PHP/Javascript]采用日历方式选择日期 郁闷php5就剩90分了 多语言显示问题 PHP面向对象学习——类的实践 一个算法问题,100分奉上
header("Content-Type:image/png");
//随机字符串种子,可以换成字母或其他英文字符
$glbVerifySeed = "AbcDefGhijkL1234567890mnOpqRstuvwxYz";
main();
function main() {
session_start();
$verifyCode = getRandomCode();
$_SESSION["verifyCode"] = $verifyCode;
$imgWidth = $_REQUEST["width"];
$imgHeight = $_REQUEST["height"];
$imgFont = $_REQUEST["font"];
if($imgWidth == "") $imgWidth = 50;
if($imgHeight == "") $imgHeight = 18;
if($imgFont == "") $imgFont = 6;
doOutputImg($verifyCode, $imgWidth, $imgHeight, $imgFont);
}
//获取随机数字字符串
function getRandomCode($length=4) {
global $glbVerifySeed;
$bgnIdx = 0;
$endIdx = strlen($glbVerifySeed)-1;
$code = "";
for($i=0; $i<$length; $i++) {
$curPos = rand($bgnIdx, $endIdx);
$code .= substr($glbVerifySeed, $curPos, 1);
}
return $code;
}
//输出校验码图像
function doOutputImg($string, $imgWidth, $imgHeight, $imgFont,
$imgFgColorArr=array(0,0,0), $imgBgColorArr=array(255,255,255)) {
$image = imagecreatetruecolor($imgWidth, $imgHeight); //用白色背景加黑色边框画个方框
$backColor = imagecolorallocate($image, 255, 255, 255);
$borderColor = imagecolorallocate($image, 255, 255, 255);
imagefilledrectangle($image, 0, 0, $imgWidth - 1, $imgHeight - 1, $backColor);
imagerectangle($image, 0, 0, $imgWidth - 1, $imgHeight - 1, $borderColor); $imgFgColor = imagecolorallocate ($image, $imgFgColorArr[0], $imgFgColorArr[1], $imgFgColorArr[2]);
doDrawStr($image, $string, $imgFgColor, $imgFont);
doPollute($image, 64); header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
} //画出校验码
function doDrawStr($image, $string, $color, $imgFont) {
$imgWidth = imagesx($image);
$imgHeight = imagesy($image);
$count = strlen($string);
$xpace = ($imgWidth/$count);
$x = ($xpace-6)/2;
$y = ($imgHeight/2-8);
for ($p = 0; $p<$count; $p ++) {
$xoff = rand(-2, +2);
$yoff = rand(-2, +2);
$curChar = substr($string, $p, 1);
imagestring($image, $imgFont, $x+$xoff, $y+$yoff, $curChar, $color);
$x += $xpace;
} return 0;
}
//画出一些杂点
function doPollute($image, $times) {
$imgWidth = imagesx($image);
$imgHeight = imagesy($image);
for($j=0; $j<$times; $j++) {
$x = rand(0, $imgWidth);
$y = rand(0, $imgHeight);
$color = imagecolorallocate($image, rand(0,255), rand(0,255), rand(0,255));
imagesetpixel($image, $x, $y, $color);
}
}
?>