[eluser]sofbas[/eluser]
[quote author="chamu_cfi" date="1229911391"]
when a user is trying to access a specific URL which is protected, if the user is not connected is redirected to the login form, but when the user has logged on is not redirected to the originally requested URL.
[/quote]
I use flashdata to store the URL. You can
set_flashdata('url', uri_string()) to set the page referred from, get the
flashdata('url') to redirect to on successful login, or you can
keep_flashdata('url') to keep the referral when the user does not login successfully.
So if I tried to access a protected URI, e.g: /admin/dashboard
in Controller admin/dashboard.php set the flashdata
Code:
//Constructor
function Dashboard()
if ( ! $this->dx_auth->is_logged_in()) {
$this->session->set_flashdata('url', uri_string());
redirect('/auth/login');
}
then in Controller auth.php, from line 99, grab the flashdata
Code:
if ($val->run() AND $this->dx_auth->login($val->set_value('username'), $val->set_value('password'), $val->set_value('remember')))
{
// Redirect to url stored in flashdata else homepage
$redirect = $this->session->flashdata('url');
redirect($redirect);
}
and line 128 set keep_flashdata for when an error occurs:
Code:
// Load login page view
$this->session->keep_flashdata('url');
$this->load->view($this->dx_auth->login_view, $data);
Hope this helps. It works well enough for me.