如何使用CodeIgniter发送参数和重定向


how to send parament and redirect with CodeIgniter

我的框架是代码点火器。

我想这样做:当用户未登录并单击没有足够的权限查看它的url并且我想按当前url将用户重定向到login页面并在login之后,我将用户重定向到以前的url

例如:

//user is not login and click on below `url`. I want to keep `profile` address
//and redirect to `enter` page with `profile` address.
www.example.com/profile
//after login, user will redirect to previous url (www.example.com/profile).

我的代码 :

function userNotLogin(){
        $cu = current_url();
        $cu = urlencode($cu);
        redirect(base_url().'index/enter/'.$cu);
}
/

/登录页面

function enter($before_url)
    {
        if($this->isLogged())
        {
            if($before_url)
            {
                var_dump($before_url);
                return;
            }else{
                redirect(base_url());
            }
        }else{
            $data = array();
            $this->view('page_register_login' , $data );
        }
    }

var_dump($before_url);返回string(5) "http:".

为此,

您需要使用user_agent CodeIgniter库。

诸如此类--

$this->load->library('user_agent');
redirect($this->agent->referrer());

它将工作100%,请使用这个...

嘟嘟——

public function login()
    {
        $this->load->library('user_agent');
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        $arr = array(
            'username' => $username,
            'password' => md5($password),
            'user_type' => 'admin'
            );
        $result = $this->common_model->getMultiple('panel_login',$arr);
        if(!empty($result )){
            $this->session->set_userdata('unique_id',$result[0]['s_no']);
            $this->session->set_userdata('username',$result[0]['username']);
            $this->session->set_userdata('password',$result[0]['password']);
            $this->session->set_userdata('type',$result[0]['user_type']);
            $this->session->set_userdata('status',$result[0]['status']);
            $this->session->set_userdata('user_activity',time());
            redirect($this->agent->referrer()); 
        }else{
            redirect('login_view');
        }
    }