I'm new at this language and I can´t understand this warning: Warning: Cannot modify header information - headers already sent by (output started at /Applications/AMPPS/www/.../users.php:316) in /Applications/AMPPS/www/.../phpgraphlib.php on line 213
I want to show some graphs about temperature, but appears the message above.
Here's my code:

phpgraphlib.php

protected function initialize() 
    {
        //header must be sent before any html or blank space output
        if (!$this->output_file) {
            header("Content-type: image/png");
    }

users.php

<!-- Temperature -->
           <div class="" id="temperatura1" name="temp">
                <?php require 'php/statics/staticsTemp.php';?>
                <h3 class="centered">Temperature</h3>
                <hr> 
                <br>
                <table class="tg" border="10">
                    <tr>
                        <th class="tg-031e">Temperature ºC</th>
                        <th class="tg-031e">Date and Time</th>
                    </tr>
                    <?php foreach ($data as $datetime => $temperature): ?>
                    <tr>
                        <td class="tg-031e"><?php echo $temperature; ?></td>
                        <td class="tg-031e"><?php echo $datetime; ?></td>
                    </tr>
                    <?php endforeach; ?>
                </table>
           </div>

Any thoughts to solve this?

Recommended Answers

All 7 Replies

Where do you call the initialize function?
The error is telling you that you are trying to set the header after you started the output.

And how i resolve this?

You need to put whole code here
so that we can find problem

This is my code from users.php:

<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
        <title>....</title>
        <meta name="generator" content="Bootply" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
         <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/foundation/5.1.1/css/normalize.css"/>
        <!-- CSS code from Bootply.com editor -->        
        <style type="text/css">
            /* BOOTSTRAP 3.x GLOBAL STYLES
-------------------------------------------------- */
            body 
            {
                padding-bottom: 40px;
                color: #5a5a5a;
                background: #000;
            }
            /* CUSTOMIZE THE NAVBAR
-------------------------------------------------- */
            /* Special class on .container surrounding .navbar, used for positioning it into place. */
            .navbar-wrapper 
            {
                position: absolute;
                top: 0;
                left: 0;
                right: 0;
                z-index: 10;
            }

            /* CUSTOMIZE THE CAROUSEL
-------------------------------------------------- */
            /* Carousel base class */
            .carousel 
            {
                margin-bottom: 60px;
            }
            /* Since positioning the image, we need to help out the caption */
            .carousel-caption 
            {
                z-index: 10;
            }
            /* Declare heights because of positioning of img element */
            .carousel .item 
            {
                height: 400px;
                background-color:#555;
            }
            .carousel img 
            {
                position: absolute;
                top: 0;
                left: 0;
                min-height: 400px;
            }

            /* MARKETING CONTENT
-------------------------------------------------- */
            /* Pad the edges of the mobile views a bit */
            .marketing 
            {
                padding-left: 15px;
                padding-right: 15px;
            }
            /* Center align the text within the three columns below the carousel */
            .marketing .col-lg-4 
            {
                text-align: center;
                margin-bottom: 20px;
            }
            .marketing h2 
            {
                font-weight: normal;
            }
            .marketing .col-lg-4 p 
            {
                margin-left: 10px;
                margin-right: 10px;
            }

            /* Featurettes
------------------------- */
            .featurette-divider 
            {
                margin: 80px 0; /* Space out the Bootstrap <hr> more */
            }
            .featurette 
            {
                padding-top: 120px; /* Vertically center images part 1: add padding above and below text. */
                overflow: hidden; /* Vertically center images part 2: clear their floats. */
            }
            .featurette-image 
            {
                margin-top: -120px; /* Vertically center images part 3: negative margin up the image the same amount of the padding to center it. */
            }
            /* Give some space on the sides of the floated elements so text doesn't run right into it. */
            .featurette-image.pull-left 
            {
                margin-right: 40px;
            }
            .featurette-image.pull-right 
            {
                margin-left: 40px;
            }
            /* Thin out the marketing headings */
            .featurette-heading 
            {
                font-size: 50px;
                font-weight: 300;
                line-height: 1;
                letter-spacing: -1px;
            }

            /* RESPONSIVE CSS
-------------------------------------------------- */
            @media (min-width: 768px) 
            {
                /* Remve the edge padding needed for mobile */
                .marketing 
                {
                    padding-left: 0;
                    padding-right: 0;
                }
                /* Navbar positioning foo */
                .navbar-wrapper 
                {
                    margin-top: 20px;
                    margin-bottom: -90px; /* Negative margin to pull up carousel. 90px is roughly margins and height of navbar. */
                }
                /* The navbar becomes detached from the top, so we round the corners */
                .navbar-wrapper .navbar 
                {
                    border-radius: 4px;
                }
                /* Bump up size of carousel content */
                .carousel-caption p 
                {
                    margin-bottom: 20px;
                    font-size: 21px;
                    line-height: 1.4;
                }
            }
            </style>
        <!--CSS to tables -->     
         <style type="text/css">
            .tg  
            {
                border-collapse:collapse;border-spacing:0;border-color:#aaa;margin:0px auto;
            }
            .tg td
            {
                font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#aaa;color:#333;background-color:#fff;text-align:center
            }
            .tg th
            {
                font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#aaa;color:#fff;background-color:#f38630;text-align:center
            }
            .tg .tg-4i69
            {
                font-size:18px;font-family:"Times New Roman", Times, serif !important;;background-color:#000000;color:#ffffff;text-align:center
            }
            .tg .tg-a6b6
            {
                font-size:18px;font-family:"Times New Roman", Times, serif !important;;text-align:center
            }
        </style>
        <!--/CSS to tables -->
    </head>
    <!-- HTML code from Bootply.com editor -->
    <body>
        <!-- Carousel -->
        <div id="myCarousel" class="carousel slide">
            <!-- Indicators -->
            <ol class="carousel-indicators">
                <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
                <li data-target="#myCarousel" data-slide-to="1"></li>
                <li data-target="#myCarousel" data-slide-to="2"></li>
            </ol>
            <div class="carousel-inner">
                <div class="item active">
                    <img src="images/cloud.jpg" class="img-responsive">
                    <div class="container">
                    <div class="carousel-caption">
                            <h1>Imagem 1</h1>
                        </div> 
                    </div>
                </div>
                <div class="item">
                    <img src="images/fires.jpeg" class="img-responsive">
                    <div class="container">
                        <div class="carousel-caption">
                            <h1>imagem 2</h1>
                            <!--<p>Bootstrap 3 still features a 12-column grid, but many of the CSS class names have completely changed.</p>
                            <p><a class="btn btn-large btn-primary" href="#">Learn more</a></p> -->
                        </div>
                    </div>
                </div>
                <div class="item">
                    <img src="images/accident.jpg" class="img-responsive">
                    <div class="container">
                        <div class="carousel-caption">
                            <h1>imagem 3</h1>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Controls -->
            <a class="left carousel-control" href="#myCarousel" data-slide="prev">
                <span class="icon-prev"></span>
            </a>
            <a class="right carousel-control" href="#myCarousel" data-slide="next">
                <span class="icon-next"></span>
            </a>  
        </div>
        <!-- /Carousel -->
       <!-- navbar wrapper --> 
        <div class="navbar-wrapper">
            <div class="container">
                <div class="navbar navbar-inverse navbar-static-top">
                    <div class="navbar-header">
                        <a class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </a>
                        <a class="navbar-brand" href="#">Eyeloon</a>
                    </div>
                    <div class="navbar-collapse collapse">
                        <ul class="nav navbar-nav">
                            <li class="active"><a href="index.html">Home</a></li>
                            <li><a href="#images">Images</a></li> 
                         <li class="sensors-dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown">Sensors <b class="caret"></b></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="#temperatura1">Temperature</a></li>
                                        <li><a href="#pressure1">Pressure</a></li>
                                        <li><a href="#moisture1">Moisture</a></li>
                                        <li><a href="#location1">GPS Location</a></li>
                                    </ul>
                            </li>   
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown">Graphs <b class="caret"></b></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="#temperatura2">Temperature</a></li>
                                        <li><a href="#pressure2">Pressure</a></li>
                                        <li><a href="#moisture2">Moisture</a></li>
                                        <li><a href="#location2">Location</a></li>
                                    </ul>
                            </li>
                         <li><a href="#">Logout</a></li>   
                        </ul>
                    </div>
                </div>
            </div><!-- /container -->
        </div>
       <!-- /navbar wrapper -->

        <!-- START THE FEATURETTES -->
       <!-- Images -->
       <div class="" id="images" name="images">
            <h1 class="centered">Images</h1>
           <hr> 
           <br>
           <hr class="featurette-divider">
       </div>
       <!-- /Images --> 
       <!-- Data Sensors -->
       <div class="" id="sensors" name="sensors">
            <h1 class="centered">Sensors</h1>
           <hr> 
           <br>
           <!-- Temperature -->
           <div class="" id="temperatura1" name="temp">
            <?php require 'php/statics/staticsTemp.php';?>
            <h3 class="centered">Temperature</h3>
                <hr> 
            <br>
                <table class="tg" border="10">
                    <tr>
                        <th class="tg-031e">Temperature ºC</th>
                        <th class="tg-031e">Date and Time</th>
                    </tr>
                    <?php foreach ($data as $datetime => $temperature): ?>
                    <tr>
                        <td class="tg-031e"><?php echo $temperature; ?></td>
                        <td class="tg-031e"><?php echo $datetime; ?></td>
                    </tr>
                    <?php endforeach; ?>
                </table>
           </div>
           <!-- /Temperature -->
           <!-- Pressure -->
           <div class="" id="pressure1" name="pres">
            <?php require 'php/statics/staticsPres.php';?>
            <h3 class="centered">Pressure</h3>
                <hr> 
            <br>
                <table class="tg" border="10">
                    <tr>
                        <th class="tg-031e">Pressao (hPa)</th>
                        <th class="tg-031e">Date and Time</th>
                    </tr>
                    <?php foreach ($data as $datetime => $pressure): ?>
                    <tr>
                        <td class="tg-031e"><?php echo $pressure; ?></td>
                        <td class="tg-031e"><?php echo $datetime; ?></td>
                    </tr>
                    <?php endforeach; ?>
                </table>
           </div>
           <!-- /Pressure -->
           <!-- Moisture -->
           <div class="" id="moisture1" name="moist">
            <?php require 'php/statics/staticsHum.php';?>
            <h3 class="centered">Moisture</h3>
                <hr> 
            <br>
                <table class="tg" border="10">
                    <tr>
                        <th class="tg-031e">Moisture (%)</th>
                        <th class="tg-031e">Date and Time</th>
                    </tr>
                    <?php foreach ($data as $datetime => $moisture): ?>
                    <tr>
                        <td class="tg-031e"><?php echo $moisture; ?></td>
                        <td class="tg-031e"><?php echo $datetime; ?></td>
                    </tr>
                    <?php endforeach; ?>
                </table>
           </div>
           <!-- /Moisture -->
           <!-- GPS Location -->
           <div class="" id="location1" name="gps">
            <?php require 'php/statics/staticsGPS.php';?>
            <h3 class="centered">Location</h3>
                <hr> 
            <br>
                <table class="tg" border="10">
                    <tr>
                        <th class="tg-031e">Latitude (º)</th>
                      <th class="tg-031e">Longitude (º)</th>  
                        <th class="tg-031e">Date and Time</th>
                    </tr>
                    <?php foreach ($data as $datetime => $latitude): ?>
                    <tr>
                            <td class="tg-031e"><?php echo $latitude; ?></td>
                        <td class="tg-031e"><?php echo $longitude; ?></td>  
                            <td class="tg-031e"><?php echo $datetime; ?></td>
                        </tr>
                    <?php endforeach; ?>
                </table>
           </div>
           <!-- /GPS Location -->
           <hr class="featurette-divider">
        </div>
       <!-- /Data Sensors --> 
       <!-- Graphs -->
       <div class="" id="graphs" name="graphs">
            <h1 class="centered">Graphs</h1>
           <hr> 
           <br>
           <!-- Temperature -->
           <div class="" id="temperatura2" name="temp">
            <h3 class="centered">Temperature</h3>
                <hr> 
           </div>
           <!-- /Temperature -->
           <!-- Pressure -->
           <div class="" id="pressure2" name="pres">
            <h3 class="centered">Pressure</h3>
                <hr> 
            <br>
           </div>
           <!-- /Pressure -->
           <!-- Moisture -->
           <div class="" id="moisture2" name="moist">
            <h3 class="centered">Moisture</h3>
                <hr> 
            <br>
           </div>
           <!-- /Moisture -->
           <!-- GPS Location -->
           <div class="" id="location2" name="gps">
            <h3 class="centered">GPS Location</h3>
                <hr> 
            <br>
           </div>
           <!-- /GPS Location -->
           <hr class="featurette-divider">
        </div>
       <!-- /Graphs -->
       <!-- /END THE FEATURETTES -->

       <!-- FOOTER -->
        <footer>
            <div class="text-center">
                <p>This Bootstrap layout is compliments of Bootply.
                <h5>  .... | ... | ... | ... | ....</h5>  
           </div>     
        </footer>
        <!-- /.container --> 
       <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>       
       <script type='text/javascript' src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
       <script type='text/javascript' src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
       <script type='text/javascript'>
            $(document).ready(function() 
            {
            });       
       </script> 
    </body>
</html>

put all require php in the begning of page together, with out any line or space

also include phpgraphlib.php in the begninng too

Member Avatar for diafol

Please read the php sticky...

http://www.daniweb.com/web-development/php/threads/435023/read-this-before-posting-a-question

and look at the Before You Ask section as well as...

Available Tutorials and Code Snippets
Here are some long running threads, tutorials and code snippets explaining common issues.
* FAQ: "Supplied argument not valid resource"
* Cannot modify header information - headers already sent
* Password protecting a site and PHP Login page and MySql

Most coding problems with PHP is that people don't use it as it was intended. They try to mix PHP and HTML (which you can do). It is an object-oriented language very similar to C++. Don't just output HTML. Embed it in strings constructed in the methods in your classes. Once everything is ready, then do your output, such as your CSS structures, headers, and then the HTML/JS data. This will allow you to better debug the code and improve performance (less network I/O to the client browser). PHP is a powerful language and can, if used properly, greatly increase the security and flexibility of your web applications.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.