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 8153423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:00:45+00:00 2026-06-06T16:00:45+00:00

Probably something simple, but heres my problem, I have implememnted a simple captcha into

  • 0

Probably something simple, but heres my problem, I have implememnted a simple captcha into my user system, but I can’t seem to use the callback form validation to check to see if the captcha is correct.

I store the answer in the users session, and on form validation I check if it is correct.

You can see it live here: http://77.96.119.180/beer/user/register
Please excuse any references to beer 😉

Here is my code:

$this->form_validation->set_rules('captcha', 'Image verification', 'trim|required|xss_clean|integer|callback_captcha_check');

Here is part of the form

// CAPTCHA
$random_word = rand(10000, 99999);
$vals = array(
    'word'   => $random_word,
    'img_path'   => './captcha/',
    'img_url'    => 'http://77.96.119.180/beer/captcha/',
    'font_path'  => './captcha/fonts/pdark.ttf',
    'img_width'  => '150',
    'img_height' => 50,
    'expiration' => 7200
);

$cap = create_captcha($vals);

// Store captcha answer in session
$this->session->set_userdata('captcha_answer', $random_word);

$content .= form_label('Please enter the numbers in the box to verify you are human (Hint: Only numbers will appear)', 'captcha');
$content .= '<div class="left" style="margin-left:20px;">' . $cap['image'] . '</div>';
$content .= form_input(array('name' => 'captcha', 'value' => '', 'class' => 'right', 'style' => 'width:75%; margin-top:5px;'));

And here is the callback function

public function captcha_check($str)
    {
        if ($str == $this->session->userdata('captcha_answer'))
        {
            // Captcha is correct
            $this->form_validation->set_message('captcha', 'The %s was wrong, please try again');
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }
  • 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-06T16:00:47+00:00Added an answer on June 6, 2026 at 4:00 pm

    your validation rules are reversed in your callback function. your return true and return false logic needs to be reversed.

    just change your if statement to this:

    if ($str != $this->session->userdata('captcha_answer'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple, but probably common problem on how to inject HTML inside
This is probably something really simple but I cant see what! Any images I
I'm trying to do something fairly simple, but for the reason of me probably
I'm at my wits end, and it's probably something really simple. Basically I've have
I'm trying to do something which is probably very simple, I have a directory
I realize it's probably something strange, but here is what I have. I have
I have a strange problem which probably has a very simple solution, I just
This problem is probably very simple to solve but it is not clear to
I think this is probably something simple, but after an hour of searching, I've
This is probably something really simple that I am blind to see, but the

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.