0

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

if you need to check logged in status on each page, then just extend the CI_Controller construct
@Rooneyl true. Or you can make method in MY_Controller and check logged in status on selective controller
I would have two extended controllers; one for logged in and another for general access. Both of these could extend MY_Controller is there was common methods to both.
use redirect('profile/' . $username); rather than base_url() as redirect automatically does this for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.