I have a few pages that require login, so all controllers that link to these pages start with

$this->checkSession();
//...rest of the code

CheckSession should verify the session is still live, otherwise display a message and stop the execution of the rest of the code in the controller:

function checkSession()
{
    if (!$this->session->userdata('is_logged_in'))
    {
        //the session has expired!
        $data['main'] = 'confirmation_message';
        $data['title'] = "Session expired";
        $this->load->vars($data);
        $this->load->view('template');
        exit();
    }
}

. I was expecting these instructions to happen in sequence, but I only get a blank page. How can I make sure exit() gets executed only after all views are loaded?

Comments

Is there some reason why you need exit() called?

Written by Thorpe Obazee

Accepted Answer

In this case you should not use exit, what you should do if the session is not valid is redirect your app using example:

redirect('/init/login/','refresh');

Best Regards,
Pedro

Written by Pedro
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki