Well it’s not really a problem but I check if the user exist and log them in and redirect to site/members_area, but I don’t want to send the user to a specific page but i want to reload the current controller.
So if I login in index/home I would like to be redirected at index/home, how should I proceed?
in regular php I would put in the action to redirect to current page
<?php echo $_SERVER['PHP_SELF']; ?>
This is the code in the framework
function validate_credentials()
{
$this->load->model('membership_model');
$query = $this->membership_model->validate();
if($query) // if the user's credentials validated...
{
$data = array(
'username' => $this->input->post('username'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
redirect('site/members_area'); //<-- this line here should be dynamic
}
else // incorrect username or password
{
$this->index();
}
}
I solved this problem myself by having a login form in the header that always submits to one login controller, but the catch is that the header login form (which appears on every page) always has a hidden input called redirect which the actual login controller captures…
Here’s the basic set up (make sure the url helper is loaded):
The Header Login Form
The Login Controller Form
The best part is you keep setting the redirect on failure and the redirect input only gets set if you’re logging in from somewhere else.
The Controller
What’s happening here is this:
That’s just a basic example. You can obviously tweak it as needed.