Home > database >  Codeigniter Captcha Trying to access array offset on value of type bool in PHP 8.1
Codeigniter Captcha Trying to access array offset on value of type bool in PHP 8.1

Time:11-19

    $data['captcha'] = create_captcha($code);

How can fix this issue in PHP 8.1 ?

CodePudding user response:

$captcha = create_captcha($code);
$data['captcha_image'] = $captcha['image'];
$data['captcha_word'] = $captcha['word'];

CodePudding user response:

Use the PHP function "is_array()" to confirm the value is an array. If it is an array, capture it and use it as you want.

// Default value
$data['captcha_image'] = '';
$data['captcha_word'] = '';

$captcha = create_captcha($code);
if (is_array($captcha)) {
   $data['captcha_image'] = $captcha['image'];
   $data['captcha_word'] = $captcha['word'];
}
  • Related