Codeigniter implements URL redirection after user login verification

Source: Internet
Author: User
Tags codeigniter
This article mainly introduces Codeigniter to implement URL redirection after handling user login verification. if you need it, refer to the CI framework.

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:

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.