Code for Codeigniter to process URL redirection after user login verification

Source: Internet
Author: User
Code for Codeigniter to process URL redirection after user login verification

  1. Class MY_Controller extends CI_Controller
  2. {
  3. Public function _ construct ()
  4. {
  5. Parent: :__ construct ();
  6. /* Determine whether to log on and whether the current URL is auth/login */
  7. If (! $ This-> tank_auth-> is_logged_in ()
  8. & ($ This-> router-> fetch_class ()! = 'Auth' & $ this-> router-> fetch_method ()! = 'Login '))
  9. {
  10. $ Redirect = $ this-> uri-> uri_string ();
  11. If ($ _ SERVER ['query _ string'])
  12. {
  13. $ Redirect. = '? '. $ _ SERVER ['query _ string'];
  14. }
  15. /* Go to the user Login page and specify the URL to jump to after Login */
  16. Redirect ('auth/login? Redirect = '. $ redirect );
  17. }
  18. }
  19. }
  20. ?>

File: User. php

  1. Class User extends MY_Controller

  2. {
  3. Function login ()
  4. {

  5. If ($ this-> tank_auth-> is_logged_in () {// logged in

  6. Redirect ('/');

  7. } Else {

  8. // Other codes here ......
  9. /* Determine whether redirect information exists */
  10. $ Data ['redirect'] = isset ($ _ GET ['redirect'])? $ _ GET ['redirect']: '/';

  11. If ($ this-> form_validation-> run () {// validation OK

  12. If ($ this-> tank_auth-> login (
  13. $ This-> form_validation-> set_value ('login '),
  14. $ This-> form_validation-> set_value ('password '),
  15. $ This-> form_validation-> set_value ('remember '),
  16. $ Data ['login _ by_username '],
  17. $ Data ['login _ by_email ']) {// success
  18. Redirect ($ data ['redirect']);

  19. } Else {

  20. // Error handling
  21. }
  22. }
  23. $ This-> load-> view ("login_form ")
  24. }
  25. }
  26. /*
  27. Note: in login_form, Note that the form address for submitting the form:
  28. */
  29. }?>

Note the following in login_form:

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.