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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:01:28+00:00 2026-06-05T19:01:28+00:00

I am using the codeigniter framework and I am trying to implement the tankauth

  • 0

I am using the codeigniter framework and I am trying to implement the tankauth authentication. It works well for regular pages. In the __construct of the controller, I put the

if (!authenticated) { redirect('auth'); }

there so that it protects all of the functions in the controller. This works fine if the user’s credentials time out and they try to load a new page, it just redirects them to the auth page so they can login again. However, I get an infinite loop if the function in the controller is called via ajax. I assume because it is trying to send the redirect headers when the page is already loaded.

What is the correct way to protect ajax calls and redirect the user to the auth page when someone who is no logged in tries to call the function?

Thanks!

  • 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-05T19:01:30+00:00Added an answer on June 5, 2026 at 7:01 pm

    I am not familiar with tankauth in general, so there may be a better way, but in general, instead of calling the redirect from the controller, you need to return a message (e.g. in JSON) and then terminate the script, rather than redirecting.

    The client side Javascript that made the Ajax call, then checks the response and if it indicates the user was logged out, use javascript to redirect to the login (window.location). If you send a redirect on a page that was requested via Ajax, it doesn’t cause the browser to redirect, the Ajax call simply follows the redirect and the result of the Ajax call is whatever HTML your login page returns.

    So it might look like this:

    if (!authenticated) {
        if (is_ajax_call) {
            echo json_encode(array('error' => 'loggedout'));
            exit;
        } else {
            redirect('auth');
        }
    }
    

    The the Javascript checks to see if the response contains an error key, and if it is loggedout, it should redirect the user’s browser to your login page.

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

Sidebar

Related Questions

I am using codeigniter framework. where should i sanitize PHP input - controller or
I'm trying using ElasticSearch with Codeigniter framework. What i did is just install ElasticSearch
I'm trying to dynamically create tables in MySQL , using CodeIgniter PHP framework: if($colname
I am using the framework codeigniter and trying to use jquery for the purpose
I created a website using CodeIgniter Framework 2.1.0 that was originally working well. Yesterday,
I'm writing a PHP application using codeigniter framework. I'm trying to add a tool
I'm using the wiredesigns moduler extentions framework with codeigniter and I'm trying to find
I'm using codeigniter framework and I'm getting this error when I've submitted my form:
I am using Codeigniter framework and I have a form with input fields. When
I am using codeigniter framework for my site and I have done two site

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.