Php 使用community auth codeigniter登录后重定向

Php 使用community auth codeigniter登录后重定向,php,codeigniter,authentication,redirect,Php,Codeigniter,Authentication,Redirect,我无法理解如何将用户重定向到他登录后使用的上一个URL 如果用户没有查看权限,我的控制器中有以下代码(因此我将他重定向到登录页面): Auth控制器中的我的登录函数如下所示: public function login() { // Method should not be directly accessible if ($this->uri->uri_string() == 'user/login/login') sh

我无法理解如何将用户重定向到他登录后使用的上一个URL

如果用户没有查看权限,我的控制器中有以下代码(因此我将他重定向到登录页面):

Auth控制器中的我的登录函数如下所示:

public function login()
    {
        // Method should not be directly accessible
        if ($this->uri->uri_string() == 'user/login/login')
            show_404();

        if (strtolower($_SERVER['REQUEST_METHOD']) == 'post')
            $this->require_min_level(1);

        $this->setup_login_form();

        // Passing Variables
        $data['title'] = lang('page_title_login');
        $data['class'] = 'login';
        $data['description'] = lang('meta_desc_login');
        $current = $this->namemanager->getBreadName("login");
        $data['bread'] = $this->breadcrumbmanager->getBreadcrumb($current);
        $data['loadGoogleApi'] = true;
        $data['loadFacebook'] = true;

        $data['referred_from'] = $this->session->flashdata('referred_from');

        // Template declaration
        $partials = array('head' => '_master/header/head', 'navigation' => '_master/header/navigation', 'content' => 'user/login_form', 'footer' => '_master/footer/footer');
        $this->template->load('_master/master', $partials, $data);
    }
http://localhost/codeigniter/login?redirect=user
现在,当我在引用的源上执行var_转储时,它确实包含正确的值

但是,“我的登录”视图包含以下表单打开代码:

echo form_open( $login_url, ['class' => 'std-form'] );
$login_url显然是在Auth_Controller.php文件中设置的,即:

protected function setup_login_form( $optional_login = FALSE )
    {
        $this->tokens->name = 'login_token';

        /**
         * Check if IP, username, or email address on hold.
         *
         * If a malicious form post set the on_hold authentication class 
         * member to TRUE, there'd be no reason to continue. Keep in mind that 
         * since an IP address may legitimately change, we shouldn't do anything 
         * drastic unless this happens more than an acceptable amount of times.
         * See the 'deny_access_at' config setting in config/authentication.php
         */
        if( $this->authentication->on_hold === TRUE )
        {
            $view_data['on_hold_message'] = 1;
        }

        // This check for on hold is for normal login attempts
        else if( $on_hold = $this->authentication->current_hold_status() )
        {
            $view_data['on_hold_message'] = 1;
        }

        // Display a login error message if there was a form post
        if( $this->authentication->login_error === TRUE )
        {
            // Display a failed login attempt message
            $view_data['login_error_mesg'] = 1;
        }

        // Redirect to specified page
        /* Original Redirect
        $redirect = $this->input->get('redirect')
            ? '?redirect=' . $this->input->get('redirect')
            : '?redirect=' . config_item('default_login_redirect');
        */

        $redirect = $this->input->get('redirect')
            ? '?redirect=' . config_item('default_login_redirect')
            : '?redirect=' . config_item('default_login_redirect');

        // If optional login, redirect to optional login's page
        if( $optional_login )
        {
            $redirect = '?redirect=' . urlencode( $this->uri->uri_string() );

            $view_data['optional_login'] = TRUE;
        }

        // Set the link protocol
        $link_protocol = USE_SSL ? 'https' : NULL;

        // Load URL helper for site_url function
        $this->load->helper('url');

        // Set the login URL
        $view_data['login_url'] = site_url( LOGIN_PAGE . $redirect, $link_protocol );

        $this->load->vars( $view_data );
    }
当我进入浏览器并单击“登录”按钮时,URL自动显示如下:

public function login()
    {
        // Method should not be directly accessible
        if ($this->uri->uri_string() == 'user/login/login')
            show_404();

        if (strtolower($_SERVER['REQUEST_METHOD']) == 'post')
            $this->require_min_level(1);

        $this->setup_login_form();

        // Passing Variables
        $data['title'] = lang('page_title_login');
        $data['class'] = 'login';
        $data['description'] = lang('meta_desc_login');
        $current = $this->namemanager->getBreadName("login");
        $data['bread'] = $this->breadcrumbmanager->getBreadcrumb($current);
        $data['loadGoogleApi'] = true;
        $data['loadFacebook'] = true;

        $data['referred_from'] = $this->session->flashdata('referred_from');

        // Template declaration
        $partials = array('head' => '_master/header/head', 'navigation' => '_master/header/navigation', 'content' => 'user/login_form', 'footer' => '_master/footer/footer');
        $this->template->load('_master/master', $partials, $data);
    }
http://localhost/codeigniter/login?redirect=user

我需要做什么才能从变量重定向到引用的_(如果已填写)

将视图更改为

if (!empty($referred_from)) {
        echo form_open( $login_url . $referred_from, ['class' => 'std-form'] );
    } else {
        echo form_open( $login_url, ['class' => 'std-form'] );
    }

我成功了

将视图更改为

if (!empty($referred_from)) {
        echo form_open( $login_url . $referred_from, ['class' => 'std-form'] );
    } else {
        echo form_open( $login_url, ['class' => 'std-form'] );
    }

我成功了

将每个请求放入会话(可以在APPPATH.'core/MY_Controller.php'构造函数中执行),并在登录方法中检查会话变量是否存在。如何将请求放入MY_Controller的会话中?另外,您是指带有$redirect的setup\u login\u form方法吗?在会话变量中设置值时,请使用
current\u url()
helper。@Vickel只是一个常规url(例如)@Tpojka,这不意味着用户每次登录时都会被重定向到以前所在的位置吗?我只想在几个特定的情况下这样做,这样我就知道,只有在设置了referenced_from时,他才需要特定的重定向将每个请求放在会话中(可以在APPPATH.core/MY_Controller.php构造函数中这样做),并在login方法中检查会话变量是否存在。如何将请求放在MY_Controller的会话中?另外,您是指带有$redirect的setup\u login\u form方法吗?在会话变量中设置值时,请使用
current\u url()
helper。@Vickel只是一个常规url(例如)@Tpojka,这不意味着用户每次登录时都会被重定向到以前所在的位置吗?我只想在一些特定的情况下这样做,这样我就知道,只有当设置了refered_from时,他才需要特定的重定向是的,那也可以。是的,那也可以。