Search code examples
phpcodeigniterauthenticationcodeigniter-urlcodeigniter-routing

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


Am working on a codeigniter application. I have a login.php with the following code

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');
        }
    }

I have declared login as the default_controller.

I have view login.php which has a login form and submit action to login/login. when I click on submit button.

url-at-the-address-bar  expected-url  redirected-url
[root]                  login/login   login/login
login/login             login/login   login/login/login
login/login/login       login/login   login/login/login/login

and so on. The url keeps adding up. Tried htaccess. htaccess has effects on this issue. Please help


Solution

  • I used the suggestion by Simo, but it did not work. I finally found the answer by changing the form action to:

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