Codeigniter implements URL redirection after user login verification

Source: Internet
Author: User

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:

Copy codeThe 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:

Copy codeThe 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:
<? Php echo form_open (site_url ("/auth/login? Redirect = ". $ redirect);?>
*/
}

Note the following in login_form:

Copy codeThe Code is as follows: <? Php echo form_open (site_url ("/auth/login? Redirect = ". $ redirect);?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.