coolloon 2021-02-24 18:09 采纳率: 100%
浏览 95
已采纳

ctcms布置到linux后验证码不显示

验证码不显示字

PHP代码如下: 

<?php
/**
 * @Ctcms open source management system
 * @copyright 2016-2017 ctcms.cn. All rights reserved.
 * @Author:Chi Tu
 * @Dtime:2016-08-11
 */
defined('BASEPATH') OR exit('No direct script access allowed');
class Code extends Ctcms_Controller {

	function __construct(){
		parent::__construct();
	}

	public function index()
	{
		//主要参数
		$font_size = (int)$this->input->get('size', TRUE);
		$img_width = (int)$this->input->get('w', TRUE);
		$img_height = (int)$this->input->get('h', TRUE);
		$word_type = (int)$this->input->get('type', TRUE);
		if($font_size == 0) $font_size = 20;
		if($img_width == 0) $img_width = 110;
		if($img_height == 0) $img_height = 50;
		if($word_type == 0) $word_type = 3;   // 1:数字 2:英文 3:混合
		$font_file  = '../texb.ttf';

		//创建图片,并设置背景色
		$im = @imagecreate($img_width, $img_height);
		imagecolorallocate($im, 192,192,192);
		
		//获取随机字符
		if($word_type == 1) {
			$verifyCode = implode('', range(2, 9));
		}elseif ($word_type == 2) {
			$verifyCode = implode('', range('A', 'Z'));
		}else{
			$verifyCode = implode('', array_merge(range(2, 9),range('A', 'Z')));
			$verifyCode = str_replace(array('I','O'), array('P','N'), $verifyCode);
		}
		//打乱字符串
		$verifyCode = str_shuffle($verifyCode);
		$rndstring = substr($verifyCode,0,4);
		//echo $rndstring;exit;

		$this->cookie->set_cookie('codes', strtolower($rndstring), time()+1800);
		$rndcodelen = strlen($rndstring);

		//干扰线  
		for($i = 0; $i < 5; $i++) {  
			$color = imagecolorallocate($im, 0, 0, 0);  
			imageline($im, rand(0, $img_width), rand(0, $img_height), rand(0, $img_width), rand(0, $img_height), $color);  
		}

		//画边框
		//$bordercolor = imagecolorallocate($im, 0, 0, 0);
		//imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $bordercolor);
		
		//输出文字
		for($i = 0;$i < $rndcodelen;$i++){
			$rndstring[$i] = strtoupper($rndstring[$i]);
			$c_fontColor = imagecolorallocate($im, 0, 0, 0);
			$y_pos = $i == 0 ? 10 : $i * ($font_size + 8);
			$c = mt_rand(0, 15);
			@imagefttext($im, $font_size, $c, $y_pos, 35, $c_fontColor, '../texb.ttf', $rndstring[$i]);
		}
		header("Pragma:no-cache\r\n");
		header("Cache-Control:no-cache\r\n");
		header("Expires:0\r\n");
		if(function_exists("imagejpeg")){
			header("content-type:image/jpeg\r\n");
			imagejpeg($im);
		}else{
			header("content-type:image/png\r\n");
			imagepng($im);
		}
		imagedestroy($im);
		exit();
	}
}

试了更换字体路径和清除bom都没用 。

  • 写回答

1条回答 默认 最新

  • 不喝水的鱼 2021-02-25 17:55
    关注

    开一下调试模式或者打开一下报错,这种可能是新服务器没有开启图像库函数导致的!

    ini_set('display_errors','On');
    error_reporting(E_ALL);
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错