CodeIgniter code that handles URL jumps after user login verification

Source: Internet
Author: User
Tags codeigniter
    1. Class My_controller extends Ci_controller
    2. {
    3. Public Function __construct ()
    4. {
    5. Parent::__construct ();
    6. /* Determine whether to log in and determine if 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. /* Jump to the user login page and specify the url*/to jump after login
    16. Redirect (' auth/login?redirect= '. $redirect);
    17. }
    18. }
    19. }
    20. ?>
Copy Code

Files: 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 ...
  9. /* Determine if there is redirect information */
  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, you need to be aware that the form address is submitted:
  28. */
  29. }?>

Copy Code

In Login_form, you need to note that the form address of the submission forms:

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