如何将 Codeigniter-2 验证码生成为有意义的词而不是代码?
How to generate Codeigniter-2 captcha as a meaningful word instead of code?
我了解到默认情况下 codeigniter-2 只能生成 字母数字 类型的验证码。我如何扩展它以生成有意义的 word ?
例如:
morning
overlooking
- 等等
生成验证码的代码示例:
$vals = array(
'img_path' => './assets/captcha/',
'img_url' => 'http://url/assets/captcha/',
'img_width' => '130',
'font_path' => './assets/fonts/Moms_typewriter.ttf',
'img_height' => '33',
'expiration' => CAPTCHA_MAX_TIME_EXPIRATION
);
$cap = create_captcha($vals);
只需使用 array
并通过循环传递元素
<?php
$ab = array('Morning','Night','welcome','im here');
$word = '';
$n = 0;
while ($n < 1)
{
$word .= $ab[mt_rand(0,9)];
$n++;
}
$vals = array(
'word' => $word,
'img_path' => './assets/captcha/',
'img_url' => base_url().'assets/captcha/',
'img_width' => '130',
'font_path' => './assets/fonts/Moms_typewriter.ttf',
'img_height' => '33',
'expiration' => CAPTCHA_MAX_TIME_EXPIRATION
);
我了解到默认情况下 codeigniter-2 只能生成 字母数字 类型的验证码。我如何扩展它以生成有意义的 word ?
例如:
morning
overlooking
- 等等
生成验证码的代码示例:
$vals = array(
'img_path' => './assets/captcha/',
'img_url' => 'http://url/assets/captcha/',
'img_width' => '130',
'font_path' => './assets/fonts/Moms_typewriter.ttf',
'img_height' => '33',
'expiration' => CAPTCHA_MAX_TIME_EXPIRATION
);
$cap = create_captcha($vals);
只需使用 array
并通过循环传递元素
<?php
$ab = array('Morning','Night','welcome','im here');
$word = '';
$n = 0;
while ($n < 1)
{
$word .= $ab[mt_rand(0,9)];
$n++;
}
$vals = array(
'word' => $word,
'img_path' => './assets/captcha/',
'img_url' => base_url().'assets/captcha/',
'img_width' => '130',
'font_path' => './assets/fonts/Moms_typewriter.ttf',
'img_height' => '33',
'expiration' => CAPTCHA_MAX_TIME_EXPIRATION
);