I am using codeigniter and Ion_auth for my application. Got them both installed and they work just fine... This is the first time i really had to go in and do a custom redirect with codeigniter(newbie at codeigniter, also not a php master but pretty self sufficient).
What i am trying to do is say someone tries to go to my custom controler (example.com/index.php/dashboard). If they go there and are logged in then they are fine, if they are not it redirects to example.com/index.php/auth/login. then upon logging in I want them to be sent back to the dashboard and not the base url. I tried to set the HTTP_REFERER in the login function like so:
$this->session->set_userdata('refered_from', $_SERVER['HTTP_REFERER']);
and the redirect (after the login logic) like so(found on many sites/forums via google, yes i searched the problem out):
if(!$this->ion_auth->logged_in())
{
// If the user is not logged in, then show the login form ( or redirect to login form )
redirect('**login url**);
} else {
// If the user is logged in then don`t let them see the the login form again and send back to the referring page.
redirect($this->session->userdata('refered_from'));
}
this errors out everytime as a 500 error.
Are you sure you are setting userdata in the right place?
Try to put a second parameter to redirect like:
redirect($this->session->userdata('refered_from'),"refresh");
That forces to redirect as a new request changing the url too.