3

I understood that codeigniter-2 by default can generate captcha in alphanumeric type only. How I can extend it to generate as a meaningful word ?

For example:

  1. morning
  2. overlooking
  3. etc.

Sample of code that generate the 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);
Nere
  • 4,097
  • 5
  • 31
  • 71

1 Answers1

2

Just use array and pass element with the loop

<?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
    );
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85