I have a few pages that require login, so all controllers that link to these pages start with
$this->checkSession(); //...rest of the code
Put the code in a variable and write it.
$html = $this->load->view('template',null,true); echo $html; exit();