CodeIgniter implements a URL jump _php instance that handles user login verification

Source: Internet
Author: User
Tags codeigniter
CodeIgniter processing user login Verification URL jump, mainly related to the my_controller.php page and login Verification Module user.php page, the specific code is as follows:

my_controller.php page:

Copy the Code code as follows: Class My_controller extends Ci_controller
{
Public Function __construct ()
{
Parent::__construct ();
/* Determine whether to log in and determine if 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 '];
}
/* Jump to the user login page and specify the url*/to jump after login
Redirect (' auth/login?redirect= '. $redirect);
}
}
}

user.php page:

Copy the Code code as follows: Class User extends My_controller
{
function Login ()
{

if ($this->tank_auth->is_logged_in ()) {//logged in
Redirect ('/');

} else {
Other codes ...
/* Determine if there is redirect information */
$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, you need to be aware that the form address is submitted:

*/
}

It is important to note in Login_form that the form address of the submission forms is:

Copy the Code code 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.