首页 新闻 会员 周边 捐助

thinkphp sae 版验证码图片出不来,

0
悬赏园豆:5 [已关闭问题] 关闭于 2015-08-20 11:19

获取验证码时出来这个错误:

Resource interpreted as Image but transferred with MIME type text/html:

 获取验证码的代码如下:

import('ORG.Util.Image');
        ob_end_clean();
        Image::buildImageVerify();

buildImageVerify函数如下:

tatic function buildImageVerify($length=4, $mode=1, $type='png', $width=48, $height=22, $verifyName='verify') {
        $vcode = Think::instance('SaeVcode');
        session($verifyName, md5($vcode->answer()));
        $question = $vcode->question();
        header('Location:' . $question['img_url']);
    }

在网上找了个方法 ,说是用下面这个函数替换,可是换了 后,出来一堆乱码,

static function buildImageVerify($length=4, $mode=1, $type='png', $width=48, $height=22, $verifyName='verify') {
import('ORG.Util.String');
$randval = String::randString($length, $mode);
session($verifyName, md5($randval));
$width = ($length * 10 + 10) > $width ? $length * 10 + 10 : $width;
if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
$im = imagecreatetruecolor($width, $height);
} else {
$im = imagecreate($width, $height);
}
$r = Array(225, 255, 255, 223);
$g = Array(225, 236, 237, 255);
$b = Array(225, 236, 166, 125);
$key = mt_rand(0, 3);

$backColor = imagecolorallocate($im, $r[$key], $g[$key], $b[$key]); //背景色(随机)
$borderColor = imagecolorallocate($im, 100, 100, 100); //边框色
imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
$stringColor = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
// 干扰
for ($i = 0; $i < 10; $i++) {
imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44, $stringColor);
}
for ($i = 0; $i < 25; $i++) {
imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $stringColor);
}
for ($i = 0; $i < $length; $i++) {
imagestring($im, 5, $i * 10 + 5, mt_rand(1, 8), $randval{$i}, $stringColor);
}
Image::output($im, $type);
}

xqnq2007的主页 xqnq2007 | 初学一级 | 园豆:21
提问于:2015-07-04 16:21
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册