SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    include a header file (simple question i think!)

    I have several files which all include header.inc.php at the beginning, and footer.inc.php at the end. I now want to add an if statement like this:

    header.inc.php:

    PHP Code:
    <? if(== y) { ?>
    footer.inc.php:

    PHP Code:
    <? ?>
    (so that the page content is only displayed if the if evaluates to true). However, this doesn't work because I have left an open curly brace { at the end of header.inc.php!! How can I make it so that the content only displays when the if statement evaluates to true? I do not want to have to modify ANY content in the main page content file, I only want to modify header.inc.php and footer.inc.php.

    TIA in advance,

    Shai

  2. #2
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might be able to do this:

    header.inc.php
    PHP Code:
    ob_start(); 
    footer.inc.php;
    PHP Code:
    if(x==y) {
    ob_end_clean();

    That will prevent everything in your main files from displaying using output buffers. Basically, the page is not sent to the user immediately, instead it is processed, and when it comes to footer.inc.php it destroys the buffer.

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    great! it worked - thanks so much!!

    just out of curiousity, how come if x does not equal y then the content is actually displayed? does everything from the output buffer get displayed at the end of the script automatically? i.e. why do we not have to say

    PHP Code:
    } else {

    ob_end_flush();



  4. #4
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You were correct in saying that any un-destroyed/cleaned buffer will automatically output itself. You could use ob_end_flush() if you wanted, it wouldn't really make much of a difference.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •