I have a site with a default controller home. There is a login form on the home page, and pressing the login button calls the function validate_credentials(), a function in the home controller.
When a user fails to enter correct login info, from within the validate_credentials function I call:
$this->index()
Which basically reloads the homepage, and fills in the email address form with the previous info. I would call
redirect('home');
but then I cant pre-fill the email address form unless I create a session variable.
After a user enters incorrect info, the url reads:
http://www.example.com/home/validate_credentials
I just want:
http://www.example.com
or even:
http://www.example.com/home
but using routes
$route['home'] = 'home/validate_credentials';
It actually changes the functions being called. I just want to change the url. Is this possible?
Well, I'd say that session storage (and especially flashdata) is for this exact purpose - to redirect somewhere, but pass additional data. If you don't want to, you should probably just load a view without redirecting, and then in the page use HTML5 history API to modify the contents of the url bar.
Make the validation process part of the index function, then create a session variable called is_logged_in and set it to 1 when the validate credentials passes.
Then it's as simple as doing something like this:
if($this->session->userdata('is_logged_in')==1)
{
load the page here.
} else {
load the login stuff here.
}
That way if they aren't logged in they see the login form and any form validation errors pass back to the same URL and if they are logged in they just go to the normal page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With