Codeigniter implements URL redirection after user login verification. Codeigniter processes the URL jump after User login authentication, mainly involving the My_Controller.php page and the login authentication module User. php page, the specific code is as follows: My_Controller.php page: Codeigniter handles the URL jump after User login verification, mainly involving the My_Controller.php page and the login authentication module User. php page, the specific code is as follows:
My_Controller.php page:
The code is as follows:
Class MY_Controller extends CI_Controller
{
Public function _ construct ()
{
Parent: :__ construct ();
/* Determine whether to log on and 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'];
}
/* Go to the user Login page and specify the URL to jump to after Login */
Redirect ('auth/login? Redirect = '. $ redirect );
}
}
}
User. php page:
The code is as follows:
Class User extends MY_Controller
{
Function login ()
{
If ($ this-> tank_auth-> is_logged_in () {// logged in
Redirect ('/');
} Else {
// Other codes here ......
/* Determine whether redirect information exists */
$ 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, Note that the form address for submitting the form:
*/
}
Note the following in login_form:
The code is as follows:
Export My_Controller.php page :...