Home  >  Article  >  Backend Development  >  Thinkphp3.2.3验证码显示问题!

Thinkphp3.2.3验证码显示问题!

WBOY
WBOYOriginal
2016-06-23 13:02:441044browse

Thinkphp3.2.3验证码在本地显示OK,但是放在万网的虚拟主机里后只显示背景图,不显示验证码了是怎么回事?求解


回复讨论(解决方案)

字体路径对吗?

字体路径对吗?


ThinkPHP\Library\Think\Verify\ttfs    字体路径在这个位置

应该不是字体文件路径问题,背景中好像也不是标准字体
你的两种字符不是同一个字体吧?
如果不是同一个字体,先改成一样的看看

应该不是字体文件路径问题,背景中好像也不是标准字体
你的两种字符不是同一个字体吧?
如果不是同一个字体,先改成一样的看看


这个背景图的是用默认随机的,但是我选定了某个字体,他还是不显示

是不是字体包没有上传

是不是字体包没有上传


字体包都在里面

应该不是图片生成的问题。因为背景图都生成了。
看看服务器log有没有什么警告或者错误。

试试用这个能否生成,字体那里改为你的字体。

<?php/** * vCode(m,n,x,y) m个数字  显示大小为n   边宽x   边高y * http://blog.qita.in * 自己改写记录session $code */session_start(); vCode(4, 15); //4个数字,显示大小为15 function vCode($num = 4, $size = 20, $width = 0, $height = 0) {    !$width && $width = $num * $size * 4 / 5 + 5;    !$height && $height = $size + 10;     // 去掉了 0 1 O l 等    $str = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVW";    $code = '';    for ($i = 0; $i < $num; $i++) {        $code .= $str[mt_rand(0, strlen($str)-1)];    }     // 画图像    $im = imagecreatetruecolor($width, $height);     // 定义要用到的颜色    $back_color = imagecolorallocate($im, 235, 236, 237);    $boer_color = imagecolorallocate($im, 118, 151, 199);    $text_color = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));     // 画背景    imagefilledrectangle($im, 0, 0, $width, $height, $back_color);     // 画边框    imagerectangle($im, 0, 0, $width-1, $height-1, $boer_color);     // 画干扰线    for($i = 0;$i < 5;$i++) {        $font_color = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));        imagearc($im, mt_rand(- $width, $width), mt_rand(- $height, $height), mt_rand(30, $width * 2), mt_rand(20, $height * 2), mt_rand(0, 360), mt_rand(0, 360), $font_color);    }     // 画干扰点    for($i = 0;$i < 50;$i++) {        $font_color = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));        imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $font_color);    }     // 画验证码    @imagefttext($im, $size , 0, 5, $size + 3, $text_color, 'c:\\WINDOWS\\Fonts\\simsun.ttc', $code);    $_SESSION["VerifyCode"]=$code;     header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate");    header("Content-type: image/png;charset=gb2312");    imagepng($im);    imagedestroy($im);}  ?>

字体路径不对的可能性很大,把imagefttext 那里的字体打印出来看看。

你本机应该是WIN系统吧,
万网的PHP都是linux系统,看看权限啊,

1.php文件的编码是否是utf-8无bom。
2.thinkphp如果开启入口文件的debug,验证码有可能出不来,不知道是否是版本的原因,thinkphp3.0会有这么的问题。
3.有可能是你文件路径不对,或者文件权限出现问题。

你本机应该是WIN系统吧,
万网的PHP都是linux系统,看看权限啊,


权限我给了777的

应该不是图片生成的问题。因为背景图都生成了。
看看服务器log有没有什么警告或者错误。

试试用这个能否生成,字体那里改为你的字体。

<?php/** * vCode(m,n,x,y) m个数字  显示大小为n   边宽x   边高y * http://blog.qita.in * 自己改写记录session $code */session_start(); vCode(4, 15); //4个数字,显示大小为15 function vCode($num = 4, $size = 20, $width = 0, $height = 0) {    !$width && $width = $num * $size * 4 / 5 + 5;    !$height && $height = $size + 10;     // 去掉了 0 1 O l 等    $str = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVW";    $code = '';    for ($i = 0; $i < $num; $i++) {        $code .= $str[mt_rand(0, strlen($str)-1)];    }     // 画图像    $im = imagecreatetruecolor($width, $height);     // 定义要用到的颜色    $back_color = imagecolorallocate($im, 235, 236, 237);    $boer_color = imagecolorallocate($im, 118, 151, 199);    $text_color = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));     // 画背景    imagefilledrectangle($im, 0, 0, $width, $height, $back_color);     // 画边框    imagerectangle($im, 0, 0, $width-1, $height-1, $boer_color);     // 画干扰线    for($i = 0;$i < 5;$i++) {        $font_color = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));        imagearc($im, mt_rand(- $width, $width), mt_rand(- $height, $height), mt_rand(30, $width * 2), mt_rand(20, $height * 2), mt_rand(0, 360), mt_rand(0, 360), $font_color);    }     // 画干扰点    for($i = 0;$i < 50;$i++) {        $font_color = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));        imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $font_color);    }     // 画验证码    @imagefttext($im, $size , 0, 5, $size + 3, $text_color, 'c:\\WINDOWS\\Fonts\\simsun.ttc', $code);    $_SESSION["VerifyCode"]=$code;     header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate");    header("Content-type: image/png;charset=gb2312");    imagepng($im);    imagedestroy($im);}  ?>


好的,我去试试

1.php文件的编码是否是utf-8无bom。
2.thinkphp如果开启入口文件的debug,验证码有可能出不来,不知道是否是版本的原因,thinkphp3.0会有这么的问题。
3.有可能是你文件路径不对,或者文件权限出现问题。


编码都是utf-8,而且也关闭了debug,路径也没有问题,背景图的文字也能出现,就是验证码出不来。

我给那个代码试了吗?有没什么错误提示?

我也遇到了和你一样的问题-------本地访问验证码显示正确,放在万网的服务器后发现无法显示
解决方案:
更改文件的访问权限
一开始这个文件就只有 读取和 执行的权限
我把 写入权限勾上后,就能正确显示了



写给那些和我有相同遭遇,还在迷茫当中的人!!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn