here, home.php is one controller file and i want to redirect into another controller file login.php but this code is not working. if you have any idea then plz help me...

home.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller{
    function __construct(){
        parent::__construct();
        $this->check_isvalidated();
    }

    public function index(){

        echo 'Congratulations, you are logged in.';

        echo "<br /><a href=''.base_url().'home/do_logout'>Logout</a>";
    }

    private function check_isvalidated(){
        if(! $this->session->userdata('validated')){
            redirect('login');
        }
    }

    public function do_logout(){
        $this->session->sess_destroy();
        redirect('login');
    }
}
?>

Hi,

is the URL helper automatically loaded? By enabling the log in CI you should be able to get more information about the error, just check into application/logs/. Try also to prefix the redirect link with a slash, for example:

redirect('/login');

Before redirecting, try $this->load->helper('url');. Also, try to do a redirect like so redirect('login','refresh');

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.