• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Captcha error word_length

#1
I am testing Captcha and my code is like this:

Code:
$this->load->helper('captcha');
$vals = array(
       'word'          => mt_rand (100000,1000000),
       'img_path'      => './public/captcha/',
       'img_url'       => base_url().'public/captcha/'
);
$cap = create_captcha($vals);
echo $cap['image'];die();

This works OK but if the 'word' line is commented out I get a php error Undefined variable: word_length
although the User Guide says 'If a word is not supplied, the function will generate a random ASCII string.' Is this a bug or have I made a mistake in the coding?
Reply

#2
Don't comment out the 'word' string inside the array. You can put the string with no value, or NULL value. Try something like this:

$vals = [
'word' => NULL,
'img_path' => CAPTCHA_IMG_PATH,
'img_url' => site_url('publico/imagens/captcha'),
'img_width' => '150',
'img_height' => '30',
'font_path' => FONTS_PATH . 'ArialMTRegular.ttf',
'expiration' => $this->config->item('captcha_expiration', 'captcha'),
'word_length' => 6,
'font_size' => 14,
'img_id' => 'captcha-image',
'img_alt' => 'failed-to-captcha-image',
'pool' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
'colors' => [
'background' => array(255, 255, 255),
'border' => array(255, 255, 255),
'text' => array(255, 120, 120),
'grid' => array(255, 182, 182)
]
];
$cap = create_captcha($vals);
echo $cap['image'];
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.