CodeIgniter: Dynamic post-login redirection? CodeIgniter: Dynamic post-login redirection? codeigniter codeigniter

CodeIgniter: 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


when attempt to access is intercepted:

redirect('/public/login/r'.$this->uri->uri_string());

so in your case, after redirection the url might look like this:

http://www.example.com/public/login/r/project/detail/2049

if the login is successful

$uri = $this->uri->uri_string();$redirect = substr($uri, strpos($uri, '/r/')+2);redirect($redirect);

will redirect to the original resource.

(and no, the +2 should not be +3)


Why dont you create a session value upon login and then verify it on each page necessary to secure?

Build it into a library, so you can call the following:

$this->mylibrary->login($user);

and

$this->mylibrary->is_logged_in($user); on top of each page and automatically redirect visitors to your main site.