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,路径也没有问题,背景图的文字也能出现,就是验证码出不来。
我给那个代码试了吗?有没什么错误提示?
我也遇到了和你一样的问题-------本地访问验证码显示正确,放在万网的服务器后发现无法显示
解决方案:
更改文件的访问权限
一开始这个文件就只有 读取和 执行的权限
我把 写入权限勾上后,就能正确显示了
写给那些和我有相同遭遇,还在迷茫当中的人!!

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software