如何将Codeigner-2 captcha生成为有意义的单词而不是代码


How to generate Codeigniter-2 captcha as a meaningful word instead of code?

我了解到codeigner-2默认情况下只能生成字母数字类型的captcha。如何将其扩展为生成有意义的单词

例如:

  1. morning
  2. overlooking
  3. 等等

生成captcha的代码示例:

$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
    );