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

  • Home
  • SEARCH
  • 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 8707771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:57:10+00:00 2026-06-13T03:57:10+00:00

I have created some form for inserting data into database and for checking if

  • 0

I have created some form for inserting data into database and for checking if the data was sent from human I have used CAPTCHA which is already integrated to CI.

This is my controller:

    $checkrules = array(
        'img_path' => realpath(APPPATH . '../upload/checking/img') . '/',
        'img_url' => base_url() . 'upload/checking/img/',
        'font_path' => realpath(APPPATH . '../upload/checking/font.ttf'),
        'img_width' => 150,
        'img_height' => 30,
        'expiration' => 7200
    );

    $check = create_captcha($checkrules);
    $data['checkimg'] = $check['image'];

    $this->form_validation->set_rules('name', 'Name', 'required|max_length[40]|xss_clean');
    $this->form_validation->set_rules('email', 'E-mail', 'required|valid_email|xss_clean');
    $this->form_validation->set_rules('website', 'Website', 'max_length[80]|prep_url|xss_clean');
    $this->form_validation->set_rules('comment', 'Comment', 'required|xss_clean');
    $this->form_validation->set_rules('check', 'Check', 'required|xss_clean');

    if ($this->form_validation->run() == FALSE)
    {
        $this->load->view('cms/theme', $data);
    }
    else
    {
        echo "success";
        $this->load->view('cms/theme', $data);
    }

My question now is what’s the best way to validate CAPTCHA?

1.) Creating callback, which I have already done, but there was problem because when I send form is error with new CAPTCHA code.

2.) Inserting CAPTCHA’s code into database and check from it. Problem is because there will be a lot of loading database and it will be very busy.

And second question. Is this CAPTCHA saving only .jpg pictures in folder or it can be any other format there? (I’m asking this because I want to delete this captcha’s after they are used.)

  • 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-13T03:57:10+00:00Added an answer on June 13, 2026 at 3:57 am
     * Example of captcha validation without database useage
     * Instead of it used session to store captcha value
     * The images will be deleted after the use
    

    public function index()
    {   
        $this->load->helper(array('form', 'url','captcha'));
        $this->load->library('form_validation');
    
           $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
           $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
           $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
           $this->form_validation->set_rules('captcha', 'Captcha', 'callback_validate_captcha');
    
        if($this->form_validation->run() == FALSE)
           {
    
            $original_string = array_merge(range(0,9), range('a','z'), range('A', 'Z'));
            $original_string = implode("", $original_string);
            $captcha = substr(str_shuffle($original_string), 0, 6);
    
             //Field validation failed.  User redirected to login page
            $vals = array(
                    'word' => $captcha,
                    'img_path' => './captcha/',
                    'img_url' => 'http://mycodeignitor.org/captcha/',
                    'font_path' => BASEPATH.'fonts/texb.ttf',
                    'img_width' => 150,
                    'img_height' => 50,
                    'expiration' => 7200
            );
    
            $cap = create_captcha($vals);
            $data['image'] = $cap['image'];
    
            if(file_exists(BASEPATH."../captcha/".$this->session->userdata['image']))
                unlink(BASEPATH."../captcha/".$this->session->userdata['image']);
    
            $this->session->set_userdata(array('captcha'=>$captcha, 'image' => $cap['time'].'.jpg'));
            $this->load->view('index_index',$data);
           }
           else
           {
                if(file_exists(BASEPATH."../captcha/".$this->session->userdata['image']))
                    unlink(BASEPATH."../captcha/".$this->session->userdata['image']);
    
                $this->session->unset_userdata('captcha');
                $this->session->unset_userdata('image');
                redirect('home', 'refresh');
           }
    
    
    
    }
    
    public function validate_captcha(){
        if($this->input->post('captcha') != $this->session->userdata['captcha'])
        {
            $this->form_validation->set_message('validate_captcha', 'Wrong captcha code, hmm are you the Terminator?');
            return false;
        }else{
            return true;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ASP.NET2.0. I have created a download form with some input fields
I have created some python code which creates an object in a loop, and
I am creating a travel theme in which I have created some custom posts
i have a form created with some textboxes and dropdown lists, they are updated
I have created a simple html-based web-page consisting of a form and some text,
I have created a mvc3 application. Currently saving submit form value into Session as
I have created some JQuery that will expand a div 'popup' on hover and
I have created some tests in my WPF application. Right now I am working
I have created some functional categories that I use to show/hide markup elements. However,
I have created some simple charts (of type FastLine) with MSChart and update them

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.