CodeIgniter Implementation processing user login authentication URL Jump _php Instance

Source: Internet
Author: User
Tags auth error handling codeigniter

CodeIgniter Processing User login authentication after the URL jump, mainly involved in the my_controller.php page and login Verification Module user.php page, the specific code is as follows:

my_controller.php page:

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

user.php page:

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

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

} else {
Other codes ...
* To determine whether 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 pay attention to the form address for submitting the forms:
<?php Echo Form_Open (Site_url ("/auth/login?redirect=". $redirect));?>
*/
}

Notice in the login_form that the form address for the submission is:

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