Use ob_start() and ob_end_flush()?

3 replies
Should I use ob_start() at the beginning of every script that uses header('Location: file.php') and ob_end_flush()
at the end of that same script?
#obendflush #obstart
  • Profile picture of the author TristanPerry
    If you want to surpress the output then yes, go for it.

    However... that header() command would re-direct the user to another page, thus no output would actually come anyway?

    In other words, you could have:

    <?php

    header('Location: NewPage.php');

    echo 'Blah';

    ?>

    However "Blah" would never get output since the user would get re-directed to NewPage.php?

    The output buffering functions are... well... to buffer the output As in, to delay the output of the HTML to the browser until you flush/end the output bufferer. I'm a little confused why you are thinking of using OB functions when you also intend to re-direct the user?
    Signature
    Plagiarism Guard - Protect Against Content Theft
    {{ DiscussionBoard.errors[1278479].message }}
  • Profile picture of the author KirkMcD
    Actually the "echo" after the "header" might screw up the redirect and it might not execute.
    {{ DiscussionBoard.errors[1281279].message }}
  • Profile picture of the author TristanPerry
    I agree I was just pointing out that there's no real reason to use the OB functions when re-directing.
    Signature
    Plagiarism Guard - Protect Against Content Theft
    {{ DiscussionBoard.errors[1281385].message }}

Trending Topics