0
votes

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

2

2 Answers

1
votes

Please set the base_url under application/config/config.php to http://localhost/tutorial/codeigniter. This will help you to fix the error.

Thanks

1
votes

You should set in config.php under application/config. open config.php and put below line.

$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/tutorial/codeigniter/';