ob_start() & header redirect

Hi,

I’m trying to code a page that records the page hit for our web analytics program & then redirects to another URL. The essence of the code is this:

<?php 
ob_start();
include ('../global/includes/sitestat.php');
header("Location: http://www.website.com"); /* Redirect browser */
?>

The problem is that analytics stats aren’t registering hits on this page, which makes me think that the contents of the include aren’t being output to the client’s browser before the header redirect kicks in.

Have I misunderstood the function of ob_start()? Can anyone help?

Thanks in advance for any advice.

You’ve put the output into a buffer, but doesn’t it need to be “flushed” at some point?

the contents of the include aren’t being output to the client’s browser before the header redirect kicks in.

You cannot send any output to the Browser before the line
header(“Location: http://www.website.com”);

If you try, you will get an error.
If you are not getting an error, presumably ‘…/global/includes/sitestat.php’
only does some internal action without sending output to browser.

And as observed by Mittineague, you have to end with ob_end_flush() to Send the output to the browser.