atif604
atif604

Reputation: 3

codeigniter captcha helper not working

Captcha images are not creating inside the images folder

  public function index()
  {
       $this->load->helper('captcha');
       $capt = array ('img_path' => './images/',
                      'img_url' =>   base_url() .'images/',
                      'font_path' => base_url().'system/fonts/texb.ttf',
                      'img_width' => '150',
                      'img_height' => 24,
                      'border' => 0,
                      'expiration' => 7200);

       $result = create_captcha($capt);
       $this->load->view('captchaDisplay',$result);
  }

View the captcha in captchaDisplay.php

<?php 
  echo $result ['image'];
 ?>

Upvotes: 0

Views: 909

Answers (2)

Alex
Alex

Reputation: 9265

Error lies here: echo $result ['image'];

From:

$result = create_captcha($capt);
$this->load->view('captchaDisplay',$result);

You are passing an array $result which contains word image .etc. To access in your view you can do echo $image; or better yet:

$result = create_captcha($capt);
$this->load->view('captchaDisplay', array('captcha' => $result);

and access in view via: echo $captcha['image'];

The latter is a better method if you plan on adding more view items.

Upvotes: 0

Abdulla Nilam
Abdulla Nilam

Reputation: 38609

As per your code, file Structure should be

application
images
System
index.php
.htaccess

In Controller

public function index()
{
    $this->load->helper('captcha');
    $capt = array ( 
        'img_path' => './images/', # root path
        'img_url' =>   base_url() .'images/',  # root path
        'font_path' => base_url().'system/fonts/texb.ttf',
        'img_width' => '150',
        'img_height' => 24,
        'border' => 0,
        'expiration' => 7200
    );
    $result['image'] = create_captcha($capt);
    $this->load->view('captchaDisplay',$result);
}

To show in view - Check this link

Upvotes: 1

Related Questions