Welcome Guest, Not a member yet? Register   Sign In
Go back after login
#1

[eluser]Lockzi[/eluser]
Hello,

I'm looking for the best way to do this...

I want it so that whenever a user tries to go somewhere which requires login, they get to a login screen but as soon as they logged in they should be redirected back to where they where before, to that page they tried to access but required login.

Cheers
Lockzi
#2

[eluser]sikkle[/eluser]
Just give a look into session flashdata to send user back where he was.

good luck !
#3

[eluser]Pascal Kriete[/eluser]
I don't know about best, but here's the first thing that comes to mind.

In your helper/library/whatever
Code:
if (!logged_in) {
    $current = $this->uri->uri_string();
    $this->session->set_userdata('redirect', $current);
    redirect('login/');
}

In your login controller:
Code:
/* successful login */
    $redirect =  $this->session->userdata('redirect');
    $this->session->unset_userdata('redirect');
    redirect($redirect);

Something like that should work.

EDIT: Same idea as sikkle, but this will work in 1.5.4
#4

[eluser]Lockzi[/eluser]
So you're all thinking sessions then...

The way I see it there's either a hidden post field, or javascript, or sessions.
The problem with sessions is that it's illegal to store cookies on a users computer without notification and without giving the user a possibility to refuse to use the site due to cookies.
#5

[eluser]wiredesignz[/eluser]
My login controller doesn't use cookies for redirect:

Just call the controller with the return URL attached: http://domain.com/login/admin will return to admin after successful login.

http://ellislab.com/forums/viewthread/69258/
#6

[eluser]Majd Taby[/eluser]
flashdata that's stored on your own database isn't the same. you _could_ use HTTP_REFERER..but as the manual states:

Quote:'HTTP_REFERER'
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

it cannot be trusted.
#7

[eluser]John Fuller[/eluser]
How about loading a login view instead of the normal view? Then after you login just refresh the page. So really you don't even have to redirect anywhere.
#8

[eluser]Lockzi[/eluser]
Really interesting thoughts from all of you, I'll have to look over some things before I make my final decision on which way to go, but at least now I know what the majority of you would do and have gotten some great ideas!

Thanks all!




Theme © iAndrew 2016 - Forum software by © MyBB