How to prevent an included PHP script from changing the URL of the location?


I'm including a PHP script that changes the URL.

// index.php
include "script.php";
   // This script redirects using  header("Location:");
$out = ob_get_clean();
// I use the $out data for calculations
echo $out;

Is there a simple way to counter or undo this unwanted redirect? How about:

header("Location: index.php");   // redirect back to self

But this causes an endless redirect loop... any ideas?

Or is there a way to strip out the header() calls from the $out buffer, preventing it from ever reaching the client?

Just for future references. As of PHP 5.3 there's a new function called header_remove() which helps dealing with such situations.