-1

Possible Duplicate:
Headers already sent by PHP

Ok i get this error:

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

This is the code on the page:

//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');
?>

The flow goes: if user is logged in (checkUser() returns true if logged in false if not) then it displays the content if the current users id matches the user id in the url. if not it displays a msg and redirects.

Community
  • 1
  • 1
Duice352
  • 15
  • 4
  • 1
    what is set in $content? And what happens on the files you include? – Green Black Oct 17 '12 at 19:11
  • content is currently default i just discovered it did change on the default page and now it wont let me change the header – Duice352 Oct 17 '12 at 19:13
  • 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 – Duice352 Oct 17 '12 at 19:15
  • I would review your htaccess/apache redirects as well, and try using an alternate browser since the html of the page could well be cached with an older/broken or the like. – Kzqai Oct 17 '12 at 19:17

2 Answers2

1

I suspect your actual problem is:

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

or

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

Since if those return the right booleans, the $content variable will never be set, and you will get the error with include('');

In general, I suggest setting up tests, or their lesser cousins, asserts to ensure that you are getting the right logic flow. Also, set your defaults early and broadly. These steps will help reduce debugging complexity.

Kzqai
  • 22,588
  • 25
  • 105
  • 137
  • ok ill look into that as well – Duice352 Oct 17 '12 at 19:20
  • well then wouldnt it show the else echo – Duice352 Oct 17 '12 at 19:21
  • The error could easily be over-riding the whole echo. I doubt php bothers giving any non-error output when a blank or null include path is given it, it probably errors out on the code and skips echoing any info for you. – Kzqai Oct 17 '12 at 19:26
0

I found flipping the logic around to be quite successful as well as using a javascript redirect.

if (checkUser()){
  Display the content
 }else{
echo "<script type='text/javascript'> window.location = 'http://www.domain.com/quotesystem'</script>";
}
Duice352
  • 15
  • 4