I am new to codeigniter and I am developing a basic authentication system with session. I am using version 3.1.11
Please take note that I am developing in my localhost server.
Project url: http://localhost/tutorial/codeigniter
Login url: http://localhost/tutorial/codeigniter/login/index.php/auth/login
User profile url: http://localhost/tutorial/codeigniter/login/index.php/user/profile
Also, my login code works.
Controller: Auth.php
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('url');
}
public function login()
{
$this->form_validation->set_rules("username", "Username", "required");
$this->form_validation->set_rules("password", "Password", "required|min_length[7]");
if($this->form_validation->run() == TRUE) {
....
if ($row) {
$this->session->set_flashdata("success", "Success!!!");
$_SESSION["user_logged"] = TRUE;
$_SESSION["username"] = $user->username;
// redirect to profile page
redirect('user/profile', 'refresh');
} else {
$data['error']="<div class='alert alert-danger'>Invalid login details</div>";
}
}
$this->load->view("login", @$data);
}
Controller: User.php
class User extends CI_Controller
{
public function profile()
{
echo "Profile Page";
}
}
Problem: I want to redirect the user to http://localhost/tutorial/codeigniter/login/index.php/user/profile after they have successfully logged in. The code that I use for redirecting is redirect('user/profile', 'refresh');
The problem with the redirect code above is that it is redirected to http://localhost/tutorial/login/index.php/user/profile -- The /codeigniter is not included
Do you have any idea how can I redirect to http://localhost/tutorial/codeigniter/login/index.php/user/profile properly? Any help is greatly appreciated. Thanks