This article mainly introduces how Codeigniter performs URL redirection after user login verification. For more information, see
This article mainly introduces how Codeigniter performs URL redirection after user login verification. For more information, see
Codeigniter processes the URL jump after User login verification. It mainly involves the My_Controller.php page and the logon 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: