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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:42:58+00:00 2026-06-14T01:42:58+00:00

I am having difficulty setting up a admin section with a codeigniter. I have

  • 0

I am having difficulty setting up a admin section with a codeigniter.

I have just added a new folder in controller folder called fam_Admin.

So structure is like following:

-controllers
—>fam_admin
—->-login.php

in routes.php I added the following code:
$route['fam_admin'] = "fam_admin/login";

<?php
class Login extends CI_Controller {
  public function index() {
    //$login['main_content'] = '/fam_admin/login';
    //$this -> load -> view('fam_admin/includes/template', $login);
    $this -> load -> view('fam_admin/login');
  }
  public function validate_login() {
    $username = $this -> input -> post('username');
    $password = $this -> input -> post('password');
    $this -> load -> library('form_validation');
    $this -> form_validation -> set_rules('username', 'username', 'trim|required');
    $this -> form_validation -> set_rules('password', 'password', 'trim|required|callback_credential_check');
    if ($this -> form_validation -> run() == FALSE) {
      $this -> load -> view('fam_admin/login');
    }
  }
  public function credential_check() {
    //Field validation succeeded.&nbsp; Validate against database
    $username = $this -> input -> post('username');
    $password = $this -> input -> post('password');
    $this -> load -> model('fam_admin/admin');
    //query the database
    $query = $this -> admin -> check_login($username, $password);
    if (!$query) {
      $this -> form_validation -> set_message('login_check', 'Invalid username or password');
      return false;
      $this -> index();
    } else {
      $data = array(
        'username' => $this -> input -> post('username'),
        'is_logged_in' => true
      );
      $this -> session -> set_userdata($data);
      //redirect('fam_admin/main_section');
      redirect('site/logged_in');
    }
  }
}
?>

Above is the code for login.php but when the login credentials are validated it gives following error in google chrome. You can try it by entering false credentials and it should give you errors and load the same login form.

The website encountered an error while retrieving http://www.famtripsandinspectionvisits.com/index.php/fam_admin/login/validate_login. It may be down for maintenance or configured incorrectly.

  • 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-14T01:42:59+00:00Added an answer on June 14, 2026 at 1:42 am

    For one thing, this is an issue:

    if ( ! $query) {
        // ...
        return false;
        $this -> index();
    }
    

    Once you return something, that’s it – the rest of the code won’t run – so the index method doesn’t get called and there is no output at all.

    …but, you shouldn’t be loading views in a function that’s supposed to just handle data validation.

    I would rearrange things a bit, try simplifying your controller to this:

    class Login extends CI_Controller {
    
        public function index()
        {
            $this->load->library('form_validation');
            $this->form_validation->set_rules('username', 'username', 'trim|required');
            $this->form_validation->set_rules('password', 'password', 'trim|required');
            if ($this->form_validation->run())
            {
                $this->load->model('fam_admin/admin');
                $username = $this->input->post('username');
                $password = $this->input->post('password');
                $query = $this->admin->check_login($username, $password);
                if ($query)
                {
                    $data = array(
                        'username' => $this->input->post('username'),
                        'is_logged_in' => true
                    );
                    $this->session->set_userdata($data);
                    redirect('site/logged_in');
                }
                else
                {
                    $this->form_validation->set_message('login_check', 'Invalid username or password');
                }
            }
            $this->load->view('fam_admin/login');
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Jquery Cookie but am having difficulty setting and retrieving the info.
I am having real difficulty getting my head around the issue of setting the
Im having difficulty trying to design a database structure for the following scenario: My
I'm essentially having difficulty pass dynamic variables to a view. I have php functions
I am having difficulty setting up a simple html file using javascript to display
I am having some difficulty setting a simple keybinding in Sublime Text 2, which
I'm having a bit of difficulty setting up a regex to match a URL
I'm having difficulty configuring Zend_Form. I have a Zend_Form sub-class. The form has some
I'm having difficulty setting up a simple menu that displays results on a div
I have huge code base and I am having difficulty managing it. There are

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.