Code for Codeigniter to process URL redirection after user login verification
- 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 );
- }
- }
- }
- ?>
File: User. php
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:
-
|