Use ob_start() and ob_end_flush()?

Discussion in 'PHP' started by virtualmisc, Oct 1, 2009.

  1. #1
    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?
     
    virtualmisc, Oct 1, 2009 IP
  2. caprichoso

    caprichoso Well-Known Member

    Messages:
    433
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    110
    #2
    If a script uses header('Location: whatever...'); you shouldn't be writing HTML output.
     
    caprichoso, Oct 1, 2009 IP
  3. ManyThings

    ManyThings Greenhorn

    Messages:
    15
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #3
    ob_start() and ob_end_flush() are meant to capture everything that is suppose to output to screen to a variable for use later and certainly is not required when you do header(Location). Usually people will put

    exit;

    after header("Location...)"; to avoid further execution codes if any (say the header is in a conditional clause, i.e. if ... else header("Location...")
     
    ManyThings, Oct 2, 2009 IP
  4. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #4
    This is to be used when people get those headers already sent errors
     
    Bohra, Oct 2, 2009 IP
  5. lmao

    lmao Guest

    Messages:
    93
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    u can use ob_start as a very first statement on the first pagot ne of script in execution flow so u will not face the headers already sent errors if you use header function anywhere in page
     
    lmao, Oct 3, 2009 IP