Home >Backend Development >PHP Tutorial >Codeigniter handles the code for URL jump after user login verification

Codeigniter handles the code for URL jump after user login verification

WBOY
WBOYOriginal
2016-07-25 09:07:131169browse
  1. class MY_Controller extends CI_Controller
  2. {
  3. public function __construct()
  4. {
  5. parent::__construct();
  6. /* Determine whether to log in 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. /*Jump to the user login page, specify the URL to jump to after login*/
  16. redirect('auth/login?redirect='.$redirect);
  17. }
  18. }
  19. }
  20. ? >
Copy code

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 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, please note that the form address to submit the form is:
  28. */
  29. }?>

Copy the code

In login_form, please note that the form address of the submitted form is:

Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn