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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:30:17+00:00 2026-05-15T01:30:17+00:00

Well it’s not really a problem but I check if the user exist and

  • 0

Well it’s not really a problem but I check if the user exist and log them in and redirect to site/members_area, but I don’t want to send the user to a specific page but i want to reload the current controller.
So if I login in index/home I would like to be redirected at index/home, how should I proceed?

in regular php I would put in the action to redirect to current page

<?php echo $_SERVER['PHP_SELF']; ?>

This is the code in the framework

function validate_credentials()
    {       
        $this->load->model('membership_model');
        $query = $this->membership_model->validate();

        if($query) // if the user's credentials validated...
        {
            $data = array(
                'username' => $this->input->post('username'),
                'is_logged_in' => true
            );
            $this->session->set_userdata($data);
            redirect('site/members_area'); //<-- this line here should be dynamic
        }
        else // incorrect username or password
        {
            $this->index();
        }
    }
  • 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-05-15T01:30:17+00:00Added an answer on May 15, 2026 at 1:30 am

    I solved this problem myself by having a login form in the header that always submits to one login controller, but the catch is that the header login form (which appears on every page) always has a hidden input called redirect which the actual login controller captures…

    Here’s the basic set up (make sure the url helper is loaded):

    The Header Login Form

    <form action="/login" method="post">
        <input type="hidden" name="redirect" value="<?php echo current_url(); ?>" />
        <input type="text" name="username" value=""  />
        <input type="password" name="password" value=""  />
        <input type="submit" name="login" value="Login" id="submit">
    </form>
    

    The Login Controller Form

    <form id="login" action="" method="post">
        <input type="text" name="username" id="username" value="" />
        <input type="password" name="password" id="password" value=""/>
    
        <?php if(isset($_POST['redirect'])) : ?>
        <input type="hidden" name="redirect" value="<?php echo $_POST['redirect']; ?>" />
        <?php endif; ?>
    
        <input type="submit" name="login" id="submit" value="Login" />  
    </form>
    

    The best part is you keep setting the redirect on failure and the redirect input only gets set if you’re logging in from somewhere else.

    The Controller

    function index()
    {
        if( ! $this->form_validation->run())
        {
            // do your error handling thing
        }
        else
        {
            // log the user in, then redirect accordingly
            $this->_redirect();
        }   
    }
    
    function _redirect()
    {
        // Is there a redirect to handle?
        if( ! isset($_POST['redirect']))
        {
            redirect("site/members_area", "location");
            return;
        }
    
        // Basic check to make sure we aren't redirecting to the login page
        // current_url would be your login controller
        if($_POST['redirect'] === current_url())
        {
            redirect("site/members_area", "location");
            return;
        }
    
        redirect($_POST['redirect'], "location");
    }
    

    What’s happening here is this:

    1. User logins on a different page.
    2. The login form submits to a single login controller with a hidden input element stating where they are logging in from.
    3. The login controller processes the login, then redirects based on the input.
    4. On failed login the redirect keeps getting set again, so no matter what, the user will return to the original page.

    That’s just a basic example. You can obviously tweak it as needed.

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

Sidebar

Related Questions

Well, I'm trying to create a way of detecting if the user inputs nothing
Well, that's pretty much my whole question. I can see how they check for
Well i am not asking about the tool to compress or measure the size
Well guys, to ask the question is pretty simple, but myself, I'm having a
Well, the title/subject pretty much covers the issue. Using various examples and and the
Well, I have this jQuery image slideshow that uses the attribute control inside an
Well I have a Pop up in the WebBroswer control of the .NET Framework
Well, I get this message all the time using AdWhirl: Unable to fill ad
Well my question is simple and straightforward. Is there any way we can use
Well there are two problems both have to do with the restrictive file select

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.