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.
Frage
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.
Lösung 2
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.
Andere Tipps
function login() {
$this->load->library('user_agent'); // load user agent library
// save the redirect_back data from referral url
$this->session->set_userdata('redirect', $this->agent->referrer() );
...
}
if( $this->session->userdata('redirect') ) {
$redirect_url = $this->session->userdata('redirect_back');
$this->session->unset_userdata('redirect_back');
redirect( $redirect_url );
}