如何更改CodeIgniter Captcha生成的图像的名称?
我正在使用CodeIgniter验证码助手为我的网站生成验证码图像。它工作得非常好。但唯一的问题是,它会为验证码图像生成一个随机名称。如何更改CodeIgniter Captcha Helper生成的图像的名称?我使用了以下代码来生成我的验证码如何更改CodeIgniter Captcha生成的图像的名称?,codeigniter,captcha,Codeigniter,Captcha,我正在使用CodeIgniter验证码助手为我的网站生成验证码图像。它工作得非常好。但唯一的问题是,它会为验证码图像生成一个随机名称。如何更改CodeIgniter Captcha Helper生成的图像的名称?我使用了以下代码来生成我的验证码 $this->load->helper('captcha'); $keyword = $this->generate_random_keyword(); $vals = array( 'word' => $keyword
$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);
CodeIgniter/system/helpers/captcha\u helper.php
第231行
$img_name = $now.'.jpg';
您可以直接修改它(可能不是一个好主意,因为更新可能会覆盖)。或者,您可以通过复制原始帮助程序、修改并将其放入应用程序/helpers
中来创建自己的帮助程序
如果您想通过参数自定义名称,可以使用如下方法:
// line 42
function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '', $captcha_filename = '')
然后
但是,请注意,如果您设置$captcha\u filename
,此示例可能会覆盖同一目录中的现有验证码
因此,将captcha_helper.php
复制到application/helpers
中,在第42行和第231行(或仅231行)进行更改,保存,您应该会很好
// line 231
if ($captcha_filename != '')
{
$img_name = $captcha_filename.'.jpg';
}
else
{
$img_name = $now.'.jpg';
}