Welcome Guest, Not a member yet? Register   Sign In
how to back to the lastpage that we opened after login
#1

[eluser]yudahebat[/eluser]
I want make a login function that after login we redirect to the last page that we opened

could u help me?
thx..
#2

[eluser]Dam1an[/eluser]
so when you check if the user needs to be logged in, before redirecting them, get the current URI, and save it in flashdata, show the login form, check its the correct username/password and then redirect them (you will need to extend the flashdata once on the login form page so its available when you process the login details)
#3

[eluser]SeasonedCoder[/eluser]
Another option / usual practice is to append return url as GET parameter. But the approach offered by Dam1an seem more elegant to me.
#4

[eluser]Dam1an[/eluser]
Having it as a GET parameter (I assume you mean URI segment(s)) would get very messy if they're already on a page with half a dozen segments as you could end up with something like
Code:
/login/redirect/i/was/on/this/page/before
#5

[eluser]SeasonedCoder[/eluser]
Yep, I know. But still, some projects do stick to this approach. Though, personally, I like your flashdata approach more Smile That's why I second it.
#6

[eluser]Thorpe Obazee[/eluser]
I usually use flashdata for this thing. you can save the uri_string() of the referer

then redirect there when you have logged in.
#7

[eluser]Evil Wizard[/eluser]
I thought flashdata was for setting data to be displayed/used in the next page processing. I tend to use the $this->session->set_userdata('referer', $this->uri->uri_string()); to set the referring page
#8

[eluser]Dam1an[/eluser]
if you set the URI in the userdata, you need to remember to manually remove it yourself
It all works out the same, as with flash data, you have to extend it, and with userdata, you have to (well, you should) remove it yourself
#9

[eluser]eoinmcg[/eluser]
Another method is to have a hidden field containing $_SERVER['HTTP_REFERER'] in your login form.

On successful login you can redirect to whatever value it contained
#10

[eluser]Dam1an[/eluser]
[quote author="eoinmcg" date="1241798485"]Another method is to have a hidden field containing $_SERVER['HTTP_REFERER'] in your login form.

On successful login you can redirect to whatever value it contained[/quote]

I've had bad experiences with that, can't remember what I was trying to do, but it either wasn;t always set, or wasn;t always accurate :-S




Theme © iAndrew 2016 - Forum software by © MyBB