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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:18:08+00:00 2026-05-25T15:18:08+00:00

The issue here is that when my user logs into my app, they always

  • 0

The issue here is that when my user logs into my app, they always are redirected to the default controller.

I would like the user to be redirected to the page they were on before logging in.

So for example, if the user is reading forum post #12 (reading does not require login) and then decides to post an answer (answering requires login), once they login they should go back to post #12.

I am using PHP/Codeigniter 2.0.2 and the Tank_Auth library, and have in several of my controllers

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

    if (!$this->tank_auth->is_logged_in()) {
        redirect('/auth/login/');
    } else {

        //load stuff 
     }

My question is

What is the best way to set a return URL (Cookie? GET?), and how would that be implemented?

If you’re familiar with Tank_Auth, in which files should I make these changes?

Any roadmaps are welcome, even if you don’t use Tank_Auth.

  • 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-25T15:18:09+00:00Added an answer on May 25, 2026 at 3:18 pm

    This is the solution I’ve been using with tank_auth, it’s probably not the best, but I’ve found it works well for me.

    In the controller

    if (!$this->tank_auth->is_logged_in()){
       $encoded_uri = preg_replace('"/"', '_', $_SERVER['REQUEST_URI']);
       redirect('/login/'.$encoded_uri);        
    }elseif($this->tank_auth->is_logged_in(FALSE)){  // logged in, not activated
       redirect('/user/reactivate/');
    }else{
       //Logged IN Stuff Here
    }
    

    Modified Tank Auth Login Function (controllers/auth.php)

    function login($return_to = "")
    {
        if ($this->form_validation->run()) {
            if ($this->tank_auth->login(
                $this->form_validation->set_value('login'),
                $this->form_validation->set_value('password'),
                $this->form_validation->set_value('remember'),
                $data['login_by_username'],
                $data['login_by_email'])) {
               //...Other Stuff Here
               $decoded_uri = preg_replace('"_"','/',$return_to);
               redirect($decoded_uri);
            }
        }
    }
    

    You may need to change the preg_replace to something else if your urls have _ in them, I just used that because it works for me

    EDIT

    I’ve updated the function, this is one from another project that we heavily modified the tank auth stuff, so if stuff is a bit different, I’m sorry

    As for the passing the encode_uri stuff, I’ve added the following to the routes.php file (config/routes.php)

    $route['auth/login/(:any)'] = 'auth/login/$1';
    $route['auth/login'] = 'auth/login'; //Probably don't need this one now
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the issue: I have 2 data contexts that I would like to do
Here's the issue: I have a list of App names that I want to
Here's my issue, I'd like to mock a class that creates a thread at
Having an issue here that I have tried everything I can think of but
Sample: I've created a minimal set of files that highlight the issue here: http://uploads.omega.org.uk/Foo3.zip
I'm seeing basically the same issue described here I have a table that starts
Here is the issue I am having: I have a large query that needs
Here I am faced with an issue that I believe(or at least hope) was
Here's the issue: I have a hook in IE that reacts on WebBrowser.OnNavigateComplete2 event
So here's my issue. I have an image that I need to shrink. The

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.