Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8002827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:29:05+00:00 2026-06-04T16:29:05+00:00

I ran into a small problem what i cant figure out. I would liked

  • 0

I ran into a small problem what i cant figure out.

I would liked to use the captcha helper without database but nothing seems to be working.

in the construct i created a variable which generates a random string

   public function __construct()
   {
      parent::__construct();
      $this->rand = random_string('numeric', 4);
   }

passed this variable to the captcha values like this:

 $vals = array(
     'word'   => $this->rand,
     'img_path'  => './captcha/',
     'img_url'   => base_url() . 'captcha/',
     'font_path'    => './system/fonts/texb.ttf',
     'img_width'    => '150',
     'img_height' => 30,
     'expiration' => 7200
     );

 $cap = create_captcha($vals);

and wanted to validate it with a callback function like this

   function captcha_check()
   {
      if($this->input->post('code') != $this->rand)
      {
         $this->form_validation->set_message('captcha_check', 'Wrong captcha code, hmm are you the Terminator?');
         return false;
      }
   }

And nothing works, the problem is, captcha code is show with the image, the problem is the validation, if i type in the correct numbers in my captcha field it always showing me the error, no mather what i type in, could please someone give me a hint?

html:

  <label for="code">Count please </label>
      <?php echo $rand; ?>
  <input type="text" id="code" name="code" class="span3" />

validation line:

$this->form_validation->set_rules('code', 'Captcha', 'required|callback_captcha_check');
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:29:07+00:00Added an answer on June 4, 2026 at 4:29 pm

    Modify your callback function like this:

       function captcha_check()
       {
          if($this->input->post('code') != $this->rand)
          {
             $this->form_validation->set_message('captcha_check', 'Wrong captcha code, hmm are you the Terminator?');
             return false;
          }
          return true;
       }
    

    EDIT:

    You need to move this line $this->rand = random_string('numeric', 4); out of the constructor because on each load of the controller it generates a new string, resulting in different values on the captcha initial load and the captcha verification. Simply place it before the $vals initialization.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a small problem. I created a UITableView where the user can
I've ran into one small problem. I am dynamically generating some controls and place
Ran into a small problem when change to OpenLayers 2.11 with showing the length
Just started working with android and ran into a small problem. I am have
In my program, I ran into a problem writing a small number to a
I'm doing a project for a comapny and I ran into a small problem
I'm just started using SQL and ran into a problem. In my database, I
I've just began learning Python and I've ran into a small problem. I need
I kinda ran into a problem, I'm working on a small image site for
Ran into an Out of Stack Space error trying to serialize an ASP.Net AJAX

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.