sys_debug
sys_debug

Reputation: 4003

Codeigniter URL should change based on page

I have this controller function:

public function login()
{
                            .......
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('login');
        }
        else
        {
            if(isset($username) && isset($password))
            {

                if(isset($result) && $result->num_rows() > 0)
                {
                    $result = $result->result_array(); 
                    $data['result'] = $result;

                    $this->session->set_userdata($data);
                            $this->load->view('profile', $data);
                }else{
                    show_error('Authentication was not successful!');
                }   
            }
        }

    }else{
        $this->load->view('login');
    }
}

Once successful, it goes to profile page and shows data. The only problem is that the URL showing before user enters credentials and once the profile.php is loaded is the same i.e. domain.com/profile/login. I want that after login successful, the username of the user logged in to show so : domain.com/profile/username. Is this possible? if not, at least can I remove the login segment from URL?

Upvotes: 0

Views: 300

Answers (1)

safarov
safarov

Reputation: 7804

You can use redirect after checking data. If inputs are correct then page redirect to /profile/username if not remain on same page.

if(<success input check>)
    redirect(base_url().'profile/'.$username);
else{
    $this->load->view('login');
}

I assume that you check authorization for each page.

Upvotes: 2

Related Questions