Extended Codeigniter User login verification _ PHP Tutorial

Source: Internet
Author: User
Extended user login verification for Codeigniter. You need to modify My_Controller.php and the logon authentication module User. php of the controller. the code is as follows: login {publicfunction _ construct needs to modify My_Controller.php and the logon authentication module User. php of the controller. the code is as follows:

My_Controller.php
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'];}/* Jump to the user Login page and specify the URL to jump to after login */redirect ('auth/Login? Redirect = '. $ redirect );}}}
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:

 

Using My_Controller.php class MY_Controller extends CI_Controller {public function _ construct...

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.