CodeIgniter Processing User login authentication after the URL jump, mainly involved in the my_controller.php page and login Verification Module user.php page, the specific code is as follows:
my_controller.php page:
Copy Code code as follows:
Class My_controller extends Ci_controller
{
Public Function __construct ()
{
Parent::__construct ();
/* To determine whether to log in, to determine whether the current URL is auth/login*/
if (! $this->tank_auth->is_logged_in ()
&& ($this->router->fetch_class ()!= ' auth ' && $this->router->fetch_method ()!= ' login ')
{
$redirect = $this->uri->uri_string ();
if ($_server[' query_string '])
{
$redirect. = '? '. $_server[' query_string '];
}
/* Jump to the User landing page, specify login after the jump url*/
Redirect (' auth/login?redirect= '. $redirect);
}
}
}
user.php page:
Copy Code code as follows:
Class User extends My_controller
{
function Login ()
{
if ($this->tank_auth->is_logged_in ()) {//logged in
Redirect ('/');
} else {
Other codes ...
* To determine whether there is redirect information * *
$data [' redirect '] = Isset ($_get[' redirect '])? $_get[' redirect ']: '/';
if ($this->form_validation->run ()) {//validation ok
if ($this->tank_auth->login (
$this->form_validation->set_value (' login '),
$this->form_validation->set_value (' Password '),
$this->form_validation->set_value (' Remember '),
$data [' Login_by_username '],
$data [' Login_by_email '])) {//success
Redirect ($data [' redirect ']);
} else {
Error handling
}
}
$this->load->view ("Login_form")
}
}
/*
Note: In Login_form you need to pay attention to the form address for submitting the forms:
<?php Echo Form_Open (Site_url ("/auth/login?redirect=". $redirect));?>
*/
}
Notice in the login_form that the form address for the submission is:
Copy Code code as follows:
<?php Echo Form_Open (Site_url ("/auth/login?redirect=". $redirect));?>