-1

可能重复:
PHP 已发送的标头

好的,我收到此错误:

Warning: Cannot modify header information - headers already sent by (output started at   
/home/content/91/9646291/html/quotesystem/cpanel/index.php:1) in 
/home/content/91/9646291/html/quotesystem/cpanel/index.php on line 11

Notice: Undefined variable: content in 
/home/content/91/9646291/html/quotesystem/cpanel/index.php on line 63

Warning: include() [function.include]: Filename cannot be empty in 
/home/content/91/9646291/html/quotesystem/cpanel/index.php on line 63

Warning: include() [function.include]: Failed opening '' for inclusion 
(include_path='.:/usr/local/php5_3/lib/php') in 
/home/content/91/9646291/html/quotesystem/cpanel/index.php on line 63

这是页面上的代码:

//Check USER LOGIN IF not logged in bring to login screen else display content
if (!(checkUser())){
    header('Location: /quotesystem/index.php');

}else{

    //Get the user array to display data 
    $userArray = getUserArray();

    //Make sure that the userid in the browser is the same as current loggin in user
    if($userArray['user_id'] != $uid){

        $content = '';

        $view = (isset($_GET['view']) && $_GET['view'] != '') ? $_GET['view'] : '';

        switch ($view) {
            case 'list' :
                $content    = 'list.php';       
                $pageTitle  = 'Customer Control Panel - View Product';
                break;

            case 'changepass' :
                $content    = 'includes/changePass.php';        
                $pageTitle  = 'Customer Control Panel - Change Password';
                break;

            case 'modify' :
                $content    = 'includes/modify.php';        
                $pageTitle  = 'Customer Control Panel - Modify Product';
                break;

            case 'detail' :
                $content    = 'detail.php';
                $pageTitle  = 'Customer Control Panel - View Product Detail';
                break;

            default :
                $content    = 'main.php';       
                $pageTitle  = 'Customer Control Panel - View Info';
        }

                    if(!($content) OR $content =='') {
                        $content = 'main.php';
                        $pageTitle = 'Customer Cpanl';
                    }

    }else {
        echo  "Sorry this is for the customer's eyes only...you are being redirected to the <a href=\"http://www.domain.com/quotesystem\">homepage</a>.     ";


    }
}
include $content;

include('../admin/footer.php');
?>

流程如下:如果用户已登录(如果未登录,checkUser() 返回 true,如果未登录,则返回 true),如果当前用户 id 与 url 中的用户 id 匹配,则会显示内容。如果不是,它会显示一条消息并重定向。

4

2 回答 2

1

我怀疑你的实际问题是:

if($userArray['user_id'] != $uid){ // is $uid even set ever?  is the $userArray set with the right user_id?

或者

checkUser() // could easily be skipping the rest of the content because of this.

因为如果那些返回正确的布尔值, $content 变量将永远不会被设置,你会得到错误include('');

一般来说,我建议设置测试或它们的小表亲,断言以确保您获得正确的逻辑流程。此外,尽早和广泛地设置您的默认值。这些步骤将有助于降低调试复杂性。

于 2012-10-17T19:19:49.997 回答
0

我发现翻转逻辑以及使用 javascript 重定向非常成功。

if (checkUser()){
  Display the content
 }else{
echo "<script type='text/javascript'> window.location = 'http://www.domain.com/quotesystem'</script>";
}
于 2012-10-17T19:36:41.193 回答