tp5 验证码浏览器中显示黑屏的解决方案

来源:互联网 发布:linux oracle 卸载 编辑:程序博客网 时间:2024/05/29 09:53

tp5 验证码浏览器中显示黑屏的解决方案


因项目原因,决定使用tp5框架。app端需要验证码,由于我使用的是核心版。然后

composer require topthink/think-captcha

更新到服务器后,按照官方教程,

调用captcha_img() 出现黑屏。


解决方案:

打开vendor/topthink/think-captcha/src/目录下Captcha.php
搜索 
ob_start();
然后在该语句上方(或该语句前面)添加
ob_clean();

然后在试试,验证码是不是出来了?原理就不多说了。ob_clean清空(擦掉)输出缓冲区的,图片输出前不可有其他输出的。

composer 后,如果仅仅只是引入验证码插件按照教程使用报错的,一般需要解决一下几个问题。

vendor/composer/目录下两个文件的修改。

1.autoload_files.php

return array(//    '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',    '1cfd2761b63b0a29ed23657ea394cb2d' => $vendorDir . '/topthink/think-captcha/src/helper.php',//    'ddc3cd2a04224f9638c5d0de6a69c7e3' => $vendorDir . '/topthink/think-migration/src/config.php',//    '9e05116ddaa5b1d244b68c3993908acd' => $vendorDir . '/topthink/think-queue/src/config.php',//    '72c97b53391125cae04082a81029f42d' => $vendorDir . '/topthink/think-testing/src/config.php',);
return 那里注释掉与captcha无关的文件映射,如上。
2.autoload_psr4.php 文件添加
return array(
    'think\\composer\\' => array($vendorDir . '/topthink/think-installer/src'),
    'think\\' => array($baseDir . '/thinkphp/library/think'),
    'think\\captcha\\' => array($vendorDir . '/topthink/think-captcha/src'),

);

新增 一个命名空间的路径映射   'think\\captcha\\' => array($vendorDir . '/topthink/think-captcha/src'),如上