0

Possible Duplicate:
Cannot modify header information, headers already sent
Headers already sent by PHP

I'm trying to figure oui why when I load this controller I'm getting a cannot modify header information error. When it gets to the if statement it redirects to the login controller but doesn't actually redirect. It just loads that message with the dashboard controller loaded.

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

class Dashboard extends CI_Controller { 

public function index()
{
    //Config Defaults Start
    $msgBoxMsgs = array();//msgType = dl, info, warn, note, msg
    $cssPageAddons = '';//If you have extra CSS for this view append it here
    $jsPageAddons =  '';//If you have extra JS for this view append it here
    $metaAddons = '';//Sometimes there is a need for additional Meta Data such in the case of Facebook addon's
    $siteTitle = '';//alter only if you need something other than the default for this view.
    //Config Defaults Start


    //examples of how to use the message box system (css not included).
    //$msgBoxMsgs[] = array('msgType' => 'dl', 'theMsg' => 'This is a Blank Message Box...');

    /**********************************************************Your Coding Logic Here, Start*/

    if ($this->session->userdata('xtr') == 'yes') 
    {                                   
        $bodyContent = $this->config->item('defaultTemplate') .'/cpanel/dashboard';//which view file
        $bodyType = 'full';//type of template       
    } 
    else
    {
        redirect('login');
    }

    /***********************************************************Your Coding Logic Here, End*/

    //Double checks if any default variables have been changed, Start.
    //If msgBoxMsgs array has anything in it, if so displays it in view, else does nothing.      
    if(count($msgBoxMsgs) !== 0)
    {
        $msgBoxes = $this->msgboxes->buildMsgBoxesOutput(array('display' => 'show', 'msgs' =>$msgBoxMsgs));
    }
    else
    {
        $msgBoxes = array('display' => 'none');
    }

    if($siteTitle == '')
    {
        $siteTitle = $this->metatags->SiteTitle(); //reads 
    }

    //Double checks if any default variables have been changed, End.

    $this->data['msgBoxes'] = $msgBoxes;
    $this->data['cssPageAddons'] = $cssPageAddons;//if there is any additional CSS to add from above Variable this will send it to the view.
    $this->data['jsPageAddons'] = $jsPageAddons;//if there is any addictional JS to add from the above variable this will send it to the view.
    $this->data['siteTitle'] = $siteTitle;//defaults can be changed via models/metatags.php
    $this->data['bodyType'] = $bodyType;
    $this->data['bodyContent'] = $bodyContent;
    $this->load->view($this->config->item('defaultTemplate') .'/cpanel/index', $this->data);
}

}

/* End of file dashboard.php */ 
/* Location: ./application/controllers/dashboard.php */ 
Community
  • 1
  • 1
Jeff Davidson
  • 1,921
  • 7
  • 36
  • 60
  • Check for outpot before your redirect. There is bound to be some, maybe just whitespace. There are multiple duplicates around here for that error. – Nanne Jun 05 '12 at 10:19
  • What I don't understand is that when I echo strings instead of the variables and redirect I still get in the else part of the if statement. However if I go directly to the login controller it loads fine so how could it be that just having it redirect from the dashboard controller it comes up with that error message. – Jeff Davidson Jun 05 '12 at 10:24

1 Answers1

0

you are doing a very silly error

you are redirecting but not exitting since the execution of page will continue even after redirecting .

by putting die() or exit ;

1st option // it should be like this in if else

                          redirect('login'); //  or try ("location : login.php"); 

2nd option or try redirecting like

                          header('Location: http://login.php');     // specify the url you wanna redirect 

                          die();   //  or you can have exit();
Rinzler
  • 2,139
  • 1
  • 27
  • 44