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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:03:17+00:00 2026-05-27T16:03:17+00:00

The entire website requires a user to login before viewing the page. If the

  • 0

The entire website requires a user to login before viewing the page. If the user is not logged in, he gets redirected to the login/registration page.

Problem: When a user that is not logged in types in a url like http://www.domain.com/listings/1234 , he will be shown that page, but with a darkened page that prevents the user from interacting with the page (jQuery stuff, not a problem here), and a popup modal box with a link to the (Tank Auth) login page http://www.domain.com/login.

After logging in from the login page, the user will be redirected back to the usual page one gets after logging in, ie: http://www.domain.com but that page is passed the variable 1234.

In short: I want the user that has not logged in and has entered the website at http://www.domain.com/listings/1234 to NOT be redirected to http://www.domain.com/login yet, but instead remain on http://www.domain.com/listings/1234 and be shown a modal box with a link to the login page http://www.domain.com/login where if he logins in, he will be redirected back to http://www.domain.com/ instead of the usual page he gets after login and be passed the variable 1234.

How can this be done using Codeigniter?

This is what I have now:

Listings controller

function index(listing_id) {
    $this->load->module('auth');
    if(!$this->auth->tank_auth->is_logged_in()) {
         redirect('login');
    } 

    // Some calls to database etc here...

    $this->load->view('listings', $data);

}
  • 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-27T16:03:18+00:00Added an answer on May 27, 2026 at 4:03 pm

    There are several ways that your question can be accomplished. Hopefully this solution would give some ideas on how to accomplish this.

    The solution below uses jquery ui dialog to display the modal and jquery .ajax to handle the login form submission.

    Conditionally put this code at the bottom of you page before the </body> tag if the user is not logged in.

    <?php if($this->auth->tank_auth->is_logged_in()){ ?>
        <div id="dialog-wrap" class="modal" >
        <?php echo $this->load->view('login_form'); ?>
        </div>
        <script>
            $('#dialog-wrap').modal({
                modal: true,
                autoOpen: true,
            });
    
            $('#login-form').submit(function(){
                //use .ajax to submit login form and check credentials.
                $.ajax({
                    type: 'POST',
                    url: <?php echo base_url(); ?>"login.php",
                    data: "username="+$('username').val()+'&password='+$('password').val(),
                    dataType: 'json',
                    success: function(returnData){.
                        if(returnData.status){
                            //close modal box
                        }else {
                            //display message that login failed.
                        }
                    }
                });
    
            });
        </script>
    ?>
    

    Your ajax login controller

    function login(){
    
      //Use tank auth to validate login information.
    
      if(authentication is successful) {
        $return_data = array(
            'status'    => true,
            'msg'           => 'Login Successful'
        );
      }else {
            $return_data = array(
            'status'    => false,
            'msg'           => 'Login failed'
        );
      } 
    
      //Use echo instead of return when you are sending data back to an jquery ajax function.
      echo json_encode($data);
    }
    

    If you do it this way then you won’t have to rely on codeigniter redirects everything will be handled through ajax.

    I hope this gives you an idea of how to handle this.

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

Sidebar

Related Questions

I am working on a website that requires a btn that removes the entire
I've made a footer element that will be shown throughout my entire website. The
I'm making a website that requires ads being repeated down the length of a
I want that the unregistered users on my website, see the entire website's pages
I have an existing php website with a user system already set up (registration,
I realize that in general, you should not store user credentials directly (i.e., in
So, we have a very large and complex website that requires a lot of
I'm creating an entire website that will me a conglomeration of a bunch of
I need to make a background for a website cover the entire screen, BUT
Edit: Entire page (HTML) <!doctype html> <html> <head> <meta charset=utf-8 /> <title>jQuery Ajax Test</title>

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.