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

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

在PHP中,應使用password_hash和password_verify函數實現安全的密碼哈希處理,不應使用MD5或SHA1。1)password_hash生成包含鹽值的哈希,增強安全性。 2)password_verify驗證密碼,通過比較哈希值確保安全。 3)MD5和SHA1易受攻擊且缺乏鹽值,不適合現代密碼安全。

PHP類型提示提升代碼質量和可讀性。 1)標量類型提示:自PHP7.0起,允許在函數參數中指定基本數據類型,如int、float等。 2)返回類型提示:確保函數返回值類型的一致性。 3)聯合類型提示:自PHP8.0起,允許在函數參數或返回值中指定多個類型。 4)可空類型提示:允許包含null值,處理可能返回空值的函數。

PHP主要是過程式編程,但也支持面向對象編程(OOP);Python支持多種範式,包括OOP、函數式和過程式編程。 PHP適合web開發,Python適用於多種應用,如數據分析和機器學習。

PHP適合網頁開發和快速原型開發,Python適用於數據科學和機器學習。 1.PHP用於動態網頁開發,語法簡單,適合快速開發。 2.Python語法簡潔,適用於多領域,庫生態系統強大。

PHP起源於1994年,由RasmusLerdorf開發,最初用於跟踪網站訪問者,逐漸演變為服務器端腳本語言,廣泛應用於網頁開發。 Python由GuidovanRossum於1980年代末開發,1991年首次發布,強調代碼可讀性和簡潔性,適用於科學計算、數據分析等領域。

PHP在現代化進程中仍然重要,因為它支持大量網站和應用,並通過框架適應開發需求。 1.PHP7提升了性能並引入了新功能。 2.現代框架如Laravel、Symfony和CodeIgniter簡化開發,提高代碼質量。 3.性能優化和最佳實踐進一步提升應用效率。

PHP的核心優勢包括易於學習、強大的web開發支持、豐富的庫和框架、高性能和可擴展性、跨平台兼容性以及成本效益高。 1)易於學習和使用,適合初學者;2)與web服務器集成好,支持多種數據庫;3)擁有如Laravel等強大框架;4)通過優化可實現高性能;5)支持多種操作系統;6)開源,降低開發成本。

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