-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 を返し、ログインしていない場合は false を返します)、現在のユーザー 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('');

一般に、正しいロジック フローを取得していることを確認するために、テスト、またはその下位クラスの assert を設定することをお勧めします。また、初期設定を広範囲に設定してください。これらの手順は、デバッグの複雑さを軽減するのに役立ちます。

于 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 に答える