0

可能重复:
无法修改标头信息,标头已发送 标头
已由 PHP 发送

我试图弄清楚为什么当我加载这个控制器时我得到一个无法修改标题信息的错误。当它到达 if 语句时,它会重定向到登录控制器,但实际上并没有重定向。它只是在加载仪表板控制器的情况下加载该消息。

<?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 */ 
4

1 回答 1

0

你在做一个非常愚蠢的错误

您正在重定向但没有退出,因为即使在重定向之后页面的执行也会继续。

通过放置 die() 或 exit ;

第一个选项 // if else 中应该是这样的

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

第二个选项或尝试重定向

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

                          die();   //  or you can have exit();
于 2012-06-05T10:32:46.313 回答