Question

I have a really weird problem. I have been using CI for more than 2 years and it's the first time I found this kind of problem. I found that the redirect function is not working properly. I already load the url helper in autoload.php.

$autoload['helper'] = array('url','html','form','file');

What I want to do is to redirect the users to a controller if they call admin controller.

class Admin extends CI_Controller {
   function index(){
      redirect('secure');
   }
}

But what happen is the page redirected to the base_url. I've tried adding the second parameter of redirect with refresh or location but the result is just the same. It also happens to all redirect function in other controller. Can anyone tell me what the cause of this problem to happen?

EDIT: For additional information that might be helpful for finding the problem, here I put the code of the routes.php.

$route['default_controller'] = "frontpage";
$route['404_override'] = 'errors/page_missing';
$route['admin'] = 'secure';
Was it helpful?

Solution 2

I just figured out that the problem is caused by a function in my helper. By coincident, I use site_url() function in the helper, which is already used by the CI. I replace that function with another name and now the redirection is working perfectly. I don't know how it can affects the redirect function, though. Thanks for anybody tried to help me.

OTHER TIPS

class Admin extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
    }

    function index()
    {
         redirect('secure', 'refresh');
    }

}

I also got this issue in my project and i found some white space at the bottom of my page after closing php tag.

There must be some white space or some kind of echo before your redirect() method or at the bottom of the page.

If this is not the issue then set log threshold to 4 in 'config/config.php' and check 'application/logs' folder.

I had the same problem of redirect function's.

I found the solution by checking it's log file. Which is in \application\logs\

Then find the file which is addressed in log file and check if there is any space or any unused blank lines 'before and after the php tag "" '

If you find any space then remove it. And your redirect function would be work.

Thanks.

it may be the absence of index.php on URL that is...., http://localhost/codigniter/index.php/controll_page/function_name so., redirect will be.....!!

redirect(base_url()."index.php/controll_page/function_name");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top