Jump to content

[SOLVED] are functions 'executed' when included, or only when they're actually executed?


dead_elves

Recommended Posts

Hiya,

 

I'm relatively new to php, so please forgive if this is one of those persistent newbie questions.

 

I keep getting:

 

"Cannot modify header information - headers already sent by (output started at /home/www/damnedliars.awardspace.com/include/_interface.php:130) in ..."

 

<see code below...>

 

"_interface.php" is an include file that implements two functions, "renderMenubar()" and "renderFooter()" and nothing else. When I move the "_interface.php" include (blue) down below the "parse survey response and update" section (red), it works fine.

 

I assume something's conflicting with the cookie, but what? "interface.php" doesn't actually do anything until I call either of the two functions, which is only when I'm already parsing html. So, does php evaluate the functions as they're included, or only when they're actually called?

 

----------------------------------------------

submit.php:

----------------------------------------------

<?php

  /* external includes */

  /* ----------------- */

  //adds program settings and constants

  include_once('include/_settings.php');

 

  //adds program interface parsing

  //implements two functions - renderMenubar() and renderFooter() - nothing else  include_once

  ('include/_interface.php');.

 

  //enables data access and manipulation

  include_once('include/_data.php');

    initQuestions();

    initResults();

 

 

  /* parse survey response and update */

  /* -------------------------------- */

  if(!isset($_COOKIE['surveyed'])||$noTracking)

  {

    setcookie("surveyed", "yes", time()-1);

    setcookie("surveyed", "yes", time()+60*60*24*30);

   

    ...parsing and update code...

  }

 

  /* page settings */

  /* ------------- */

  $page_title="Thanks for Participating!";

?>

 

<html>

  <head>

    <title><?php echo $page_title;?></title>

    <link rel="stylesheet" type="text/css" href="<?php echo $styleDefault;?>"/>

  </head>

 

  <body>

    <br/>

    <div class="div_body">

      <table class="table_layout_narrow" align="center">

        <tr>

          <td class="tr_form_standard"><hr/></td>

        </tr>

        <tr class="tr_form_standard">

          <td class="td_form_header">

            <label class="label_format_level01"><?php echo($title);?></label>

          </td>

        </tr>

        <tr class="tr_form_standard">

          <td class="td_form_label">

            <label class="label_format_level03"><?php echo($message);?></label>

          </td>

        </tr>

        <tr class="tr_form_standard">

          <td class="td_layout_righthand">

            <label class="label_format_level03">

              <a href="javascript:window.close();">close</a>

            </label>

          </td>

        </tr>

        <tr>

          <td class="tr_form_standard"><hr/></td>

        </tr>

      </table>

    </div>

<?php

  renderFooter();

?>

  </body>

</html>

----------------------------------------------

_interface.php:

----------------------------------------------

<?php

  /* functions */

  /* --------- */

  //renderMenubar

  //-------------

  function renderMenubar()

  {

    global $pageSurvey;

    global $pageLogout;

    global $pageEdit;

    global $pageResults;

    global $pageUsers;

   

    echo "

<table ...lots of html...

</table>\n";

  }

 

  //renderFooter

  //------------

  function renderFooter()

  {

    global $urlLicense;

    global $fldLicense;

   

    echo "

<table ...lots of html...

</table>\n";

  }

?>

----------------------------------------------

PS. the global variables are all defined in "_settings.php"

 

Thanks...

 

i stopped reading here:

""Cannot modify header information - headers already sent by (output started at /home/www/damnedliars.awardspace.com/include/_interface.php:130) in ...""

 

 

try putting

ob_start(); at the very top of your pages. makre sure there are no white spaces before it too.

 

then put

ob_end_flush(); as the very last line of your pages.

do what play_ said. but also read the sticky at the top of this board.

in answer to your question about php evaluating functions when they're included, this is what i think.

PHP reads all code that is included but only runs the stuff that is called basicly. thats what i have thought, someone might correct me here though.

do what play_ said. but also read the sticky at the top of this board.

in answer to your question about php evaluating functions when they're included, this is what i think.

PHP reads all code that is included but only runs the stuff that is called basicly. thats what i have thought, someone might correct me here though.

'

 

Yes. I have a file called 'functions.php' where i put all my functions.

That file is included in the header.php which is included in every page. It only executes if i call a function.

 

Thanks both! I still don't get why it was doing what it was doing, but the workaround works, so I'm not complaining. I've probably got a space or a tab or something hidden somewhere in there.

 

Still, I'm gonna leave it open for a while. On my home pc the site works fine without buffering - only gives issues when I upload, so there might be some kind of server setting that forces evaluation or something... really taking a flyer now, but these are the things we need to know! ;-)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

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.