I'm building a basic CodeIgniter site that requires a login before you can access any of the site.
If a user visits some site url, something like this:
http://www.mysite.com/project/detail/2049
AND they are current logged out, I have it set to automatically kick them back to the login page.
My question is, after they login, what is the best way to redirect them to the original URL they typed in, instead of say, redirecting them to the websites homepage?
I was thinking maybe, dynamically create the URL as a hidden form element in the login form and redirect there upon a successful login... What do you guys think? Is there a better/best practice for this type of dynamic post-login redirection?
When they hit the restricted page record the uri and set it as session data with
this->session->set_userdata('redirect', 'page/uri/here');
then redirect them to the login / register
after they login check to see if 'redirect' is present with
if($this->session->userdata('redirect'))
{
redirect($this->session->userdata('redirect'));
}
if it doesn't then take them wherever you normally take them after a login
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With