像 http://localhost/CI/login/login/login 一样在CodeIgniter中复制URL


URL Duplicating in CodeIgniter Like http://localhost/CI/login/login/login

正在开发代码点火器应用程序。我有一个登录名.php使用以下代码

public function index()
    {
        $this->load->view('login');
    }
    public function login()
    {
        $username=$this->input->post('username');
        $password=$this->input->post('password');
        $data=array(
            'username'=>'$username',
            'password'=>'$password'
        );
        if(1){
            redirect($this->config->base_url().'admin');
        }
        else{
            redirect($this->config->base_url().'login');
        }
    }

我已将登录声明为default_controller。

我有查看登录.php它有一个登录表单和提交操作以登录/登录。 当我单击提交按钮时。

网址在地址栏 预期网址重定向网址[根]登录/登录登录/登录登录/登录登录/登录登录/登录/登录登录/登录/登录登录/登录登录/登录/登录/登录/登录

等等。网址不断累积。已尝试访问。htAccess 对此问题有影响。请帮忙

我使用了Simo的建议,但它没有奏效。我终于通过将表单操作更改为:

<form action="http://localhost/CI/login/login" method="post">
重定向

到其他控制器时不使用base_url(),您应该更改以下内容:

if(1){
  redirect($this->config->base_url().'admin');
}
else{
  redirect($this->config->base_url().'login');
}

对此:

$is_logged = false; // To replace with login statement.
if($is_logged)
  redirect('admin');
else
  redirect('login');