Jump to content
Sign in to follow this  
KeithLantern

Cannot modify header information

Recommended Posts

I keep getting this error Warning: Cannot modify header information - headers already sent by (output started at /home2/orangejuicea/public_html/coffeetable/logout.php:3) in /home2/orangejuicea/public_html/coffeetable/helpers/system_helper.php on line 24

I believe that something is wrong between tehse two files.  Is there anyone who can help me.  Any advice you would give would be greatly appreciated.

SYSTEM_HELPER.PHP
<?php
/*
 * Redirect To Page
*/
function redirect($page = FALSE, $message = NULL, $message_type = NULL) {
    if (is_string ($page)) {
        $location = $page;
    } else {
        $location = $_SERVER ['SCRIPT_NAME'];
    }

    //Check For Message
    if($message != NULL){
        //Set Message
        $_SESSION['message'] = $message;
    }
    //Check For Type
    if($message_type != NULL){
        //Set Message Type
        $_SESSION['message_type'] = $message_type;
    }

    //Redirect
    header ('Location: '.$location);
    exit;
}

/*
 * Display Message
 */
function displayMessage(){
    if(!empty($_SESSION['message'])) {
        
        //Assign Message Var
        $message = $_SESSION['message'];
            
        if(!empty($_SESSION['message_type'])) {
            //Assign Type Var
            $message_type = $_SESSION['message_type'];
            //Create Output
            if ($message_type == 'error') {
                echo '<div class="alert alert-danger">' . $message . '</div>';
            } else {
                echo '<div class="alert alert-success">' . $message . '</div>';
            }
        }
        //Unset Message
        unset($_SESSION['message'] );
        unset($_SESSION['message_type'] );
    } else {
        echo '';
    }
}

/*
 * Check If User Is Logged In
 */
function isLoggedIn(){
    if(isset($_SESSION['is_logged_in'])){
        return true;
    } else {
        return false;
    }
}

/*
 * Get Logged In User Info
*/
function getUser(){
    $userArray = array();
    $userArray['user_id'] = $_SESSION['user_id'];
    $userArray['username'] = $_SESSION['username'];
    $userArray['name'] = $_SESSION['name'];
    return $userArray;
}

 

 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HEADER.PHP
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Welcome To The Coffee Table</title>

   <!-- Bootstrap core CSS -->
    <link href="<?php echo BASE_URI; ?>templates/css/bootstrap.css" rel="stylesheet">
    <!-- Custom styles for this template -->
    <link href="<?php echo BASE_URI; ?>templates/css/custom.css" rel="stylesheet">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="<?php echo BASE_URI; ?>templates/js/bootstrap.js"></script>
    <script src="<?php echo BASE_URI; ?>templates/js/ckeditor/ckeditor.js"></script>
    <?php
    //Check if title is set, if not assign it
    if(!isset($title)){
        $title = SITE_TITLE;
    }
    ?>
  </head>

  <body>

    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="index.php">The Coffee Table</a>
        </div>
        <div class="collapse navbar-collapse">
          <ul class="nav navbar-nav navbar-right">
            <li class="active"><a href="index.php">Home</a></li>
            <?php if(!isLoggedIn()) : ?>
                <li><a href="register.php">Create An Account</a></li>
            <?php else : ?>
                <li><a href="create.php">Create Topic</a></li>
            <?php endif; ?>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </div>

    <div class="container">
        <div class="row">
            <div class="col-md-8">
                <div class="main-col">
                    <div class="block">
                        <h1 class="pull-left"><?php echo $title; ?></h1>
                        <h4 class="pull-right">A simple PHP forum engine</h4>
                        <div class="clearfix"></div>
                        <hr>
                        <?php displayMessage(); ?>


 

Share this post


Link to post
Share on other sites

Hi please can you let us know the content of your logout.php file  as this is where the error is, as stated in the error message.

 

It's likely that there is some output too soon,

Share this post


Link to post
Share on other sites

header() must be used before any output is displayed.

 

I don't see anywhere in your header.php code you posted that SYSTEM_HELPER.PHP is included or your redirect function is being called upon.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.