1

我正在使用 CodeIgniter Captcha Helper 为我的网站生成验证码图像。它工作得很好。但唯一的问题是它会为验证码图像生成一个随机名称。如何更改 CodeIgniter Captcha Helper 生成的图像名称?我已使用以下代码生成我的验证码。

$this->load->helper('captcha');
$keyword = $this->generate_random_keyword();
$vals = array(
    'word'  => $keyword,
    'img_path'     => './captcha/',
    'img_url'     => base_url() . '/captcha/',
    'img_width'     => '150',
    'img_height' => '35',
    'border' => 0, 
    'font_path'  => './fonts/texb.ttf',
    'expiration' => 3600
);
$captcha = create_captcha($vals);
4

1 回答 1

2

CodeIgniter/system/helpers/captcha_helper.php第 231 行

$img_name = $now.'.jpg';

您可以直接修改它(可能不是一个好主意,因为更新可能会覆盖)。或者您可以通过复制原始文件、修改并将其放入application/helpers.

如果您想通过参数自定义名称,应该这样做:

// line 42
function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '', $captcha_filename = '')

然后

// line 231
if ($captcha_filename != '')
{
    $img_name = $captcha_filename.'.jpg';
}
else
{
    $img_name = $now.'.jpg';
}

但请注意,如果您设置$captcha_filename.

因此,复制captcha_helper.phpapplication/helpers,在第 42 和 231 行(或仅 231)进行更改,保存,你应该会很好。

于 2013-09-10T18:12:15.340 回答