外贸网站建设,外贸网站建设公司,跨境电商独立站

PBOOTCMS升级到PHP 8X之后,验证码图片不显示如何解决?

时间:2026-10-27   访问量:1004

由于10月21日,PHP环境涉及两个高危远程代码执行漏洞(CVE-2026-109618、CVE-2026-109619),而新升级的PHP环境仅支持PHP 8.2及以上的版本。

很多使用PBOOT建站的,之前都是用PHP 7X版本,如果直接改成PHP 8X,则出现了各种BUG。

比如这一篇文章需要解决的就是验证码不显示的问题。

如果你的程序可以直接升级到最新版,一般可以解决这个问题。如果你做了二次开发,也不方便升级,则可以通过以下方案解决:

有一些网站后台登陆时,验证码不显示,可修改core中code.php


<?php
/**
 * @copyright (C)2016-2099 Hnaoyun Inc.
 * @author XingMeng
 * @email hnxsh@foxmail.com
 * @date 2017年2月7日
 *  生成验证码
 */
use core\extend\code\Code;

// 独立图片入口也会经过初始化和 WAF,须先声明模块绑定。/**********************************此处为修改的部分
defined('URL_BIND') || define('URL_BIND', 'code');
//**********************************此处为修改的部分

// 引入验证码类
require dirname(__FILE__) . '/init.php';

// 防止外部调用验证码图片
$form = $_SERVER['HTTP_REFERER'];
$host = $_SERVER['HTTP_HOST'];

// 修复Referer: 为空时 依然可以被外部调用 @LiuXiaoBai
if (is_null($form) || (strpos($form, '://' . $host) != 4 && strpos($form, '://' . $host) != 5)) {
    die('非法调用验证码!');
}

// 记录验证码
session_start(); // 启动会话

// 预定义配置
$config = array(
    'length'   => 4,
    'useZh'    => false,
    'math'     => false,
    'fontSize' => 18,
    'useCurve' => true,
    'useNoise' => true,
    'imageH'   => 45,
    'imageW'   => 120,
);

// 加载用户配置
if (file_exists(CONF_PATH . '/captcha.php')) {
    $config = require CONF_PATH . '/captcha.php';
}

// 获取单独配置
$config['fontSize'] = get('f','int') ?: $config['fontSize'];
$config['length'] = get('l','int') ?: $config['length'];
$config['imageW'] = get('w','int') ?: $config['imageW'];
$config['imageH'] = get('h','int') ?: $config['imageH'];
$config['useCurve'] = get('c','int') ? false : $config['useCurve'];
$config['useNoise'] = get('n','int') ? false : $config['useNoise'];

// 验证码类型
$type = get('t','int');
switch ($type)
{
case "1": // 随机验证码
    $config['useZh'] = false;
    $config['math'] = false;
    $rand = mt_rand(1, 3);
    if($rand == 2) {
        $config['useZh'] = true;
    }
    if($rand == 3) {
        $config['math'] = true;
    }
    break;
case "2": // 中文验证码
    $config['useZh'] = true;
    $config['math'] = false;
    break;
case "3": // 算术验证码
    $config['useZh'] = false;
    $config['math'] = true;
    break;
}

// 中文字体未随源码部署时,回退为英文验证码,避免 dir() 失败中断图片输出。/**********************************此处为修改的部分
$zhFontPath = dirname(__FILE__) . '/extend/code/assets/zhttfs/';
if ($config['useZh'] && !glob($zhFontPath . '*.ttf') && !glob($zhFontPath . '*.otf')) {
    $config['useZh'] = false;
}
///**********************************此处为修改的部分

// 初始化验证码
$code = new Code($config);
$code->doimg();
session('checkcode', $code->getCode());




正在加载评论…