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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:49:29+00:00 2026-06-05T17:49:29+00:00

I have a callback function that checks my login details are correct – If

  • 0

I have a callback function that checks my login details are correct – If they are wrong it returns an error (this is working fine). If the details are correct it should set the session $this->session->set_userdata('logged_in',TRUE); and then continue with the function login and be redirected to the dashboard – This redirect works fine.

In my function index(){} on any dashboard pages have the line

if($this->session->userdata('logged_in')) redirect('dashboard/home');

The line above is the one that is causing my 310 redirect but I am unsure why?

I am wanting to check if the user is logged in redirect to dashboard/home else go back to the login page home/login

Controller:

class Home extends CI_Controller {

    function __construct() {
            parent::__construct();
        }    

    public function index()
    {
        //if($this->session->userdata('logged_in')) redirect('dashboard/home');

        $data['contentMangement'] = $this->options_model->systemOptions();
        $data['pageTitle'] = 'Login';
        $data['message'] = "";
        $this->load->view('_assets/header', $data);
        $this->load->view('login', $data);
        $this->load->view('_assets/footer');
    }

    public function login() {
          $this->form_validation->set_rules('userEmail','Username', 'required|valid_email|trim|max_length[99]|xss_clean');
            $this->form_validation->set_rules('userPassword','Password', 'required|trim|max_length[200]|xss_clean|callback__checkUsernamePassword');

            if($this->form_validation->run() === FALSE) {

                $data['contentMangement'] = $this->options_model->systemOptions();
                $data['pageTitle'] = 'Login';
                $data['message'] = validation_errors('<div class="alert alert-error">', '</div>');
                $this->load->view('_assets/header', $data);
                $this->load->view('login', $data);
                $this->load->view('_assets/footer');

            }elseif($this->form_validation->run() === TRUE){

            redirect('dashboard/home');
        }
    }


    function _checkUsernamePassword() {

            $username = $this->input->post('userEmail');
            $password = $this->input->post('userPassword');

            $user = $this->user_model->check_login($username,$password);

            if(! $user)
            {
                $this->form_validation->set_message('_checkUsernamePassword', 'Sorry the details you provided have not been found');
                return FALSE;
            }else{
                 $this->session->set_userdata('logged_in',TRUE);
                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-05T17:49:31+00:00Added an answer on June 5, 2026 at 5:49 pm

    Here’s what’s happening.

    Assume, I login correctly, in your login controller, you set logged_in = TRUE, and redirect me to dashboard/home. In the index() function at dashboard/home, if logged_in = TRUE (which it is) you redirect me to dashboard/home again. Once again, you check logged_in = TRUE, and redirect me again, and so on and so forth.

    This is causing an infinite redirection loop which causes the 310 Error (Too many redirects).

    You’ll need to rework your login check. In index() in dashboard/home, do this:

    if ($this->session->userdata('logged_in') === FALSE) redirect(site_url('dashboard/login'));

    Now, when I visit dashboard home, you only redirect me away if I’m not logged in. This protects your dashboard home against non-authenticated users, while not throwing authenticated users into an infinite loop.

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

Sidebar

Related Questions

I have a callback function that check_captcha which sees if $row is ==0 or
I have a member function in a class that has a callback, but the
I have this static callback function in MyClass, and I try to call another
I'm using the HTML5 Web Database API and I have a function that checks
I know that .append() does not have any callback function, but when I try
I have a callback function that I'm using to validate a submitted video URL
In my application I have a login using ajax that returns a JSON result.
I have this code that loads on document.ready and it checks if the user
I have a list of callback functions that I need to invoke when an
I want to have one callback function after actions are done, I'm trying something

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.