如何将Codeigniter-2验证码生成为有意义的单词而不是代码?

时间:2015-06-29 03:51:36

标签: php codeigniter codeigniter-2 captcha

我知道codeigniter-2默认情况下只能生成字母数字类型的验证码。我如何将其扩展为生成有意义的单词

例如:

  1. morning
  2. overlooking
  3. 生成验证码的代码示例:

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

1 个答案:

答案 0 :(得分:2)

只需使用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
    );