CodeIgniter Forums
how to back to the lastpage that we opened after login - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: how to back to the lastpage that we opened after login (/showthread.php?tid=18493)

Pages: 1 2


how to back to the lastpage that we opened after login - El Forum - 05-08-2009

[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..


how to back to the lastpage that we opened after login - El Forum - 05-08-2009

[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)


how to back to the lastpage that we opened after login - El Forum - 05-08-2009

[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.


how to back to the lastpage that we opened after login - El Forum - 05-08-2009

[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



how to back to the lastpage that we opened after login - El Forum - 05-08-2009

[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.


how to back to the lastpage that we opened after login - El Forum - 05-08-2009

[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.


how to back to the lastpage that we opened after login - El Forum - 05-08-2009

[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


how to back to the lastpage that we opened after login - El Forum - 05-08-2009

[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


how to back to the lastpage that we opened after login - El Forum - 05-08-2009

[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


how to back to the lastpage that we opened after login - El Forum - 05-08-2009

[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