build your var like so:
$page = "<html><body>";
//buch of stuff here to determine what your page should look like
//eg: if( $this == $that ) $page .= "blah blah blah";
$page .= "</body></html>";
then once you have your page built, you would pass $page to a page that is blank, except for this:
<?php
if( isset($code) ) echo $code;
else echo("You have accessed this page incorrectly");
?>
That blank page looks for the $page. if it finds it, it writes all the code. In the end, you have a page with nothing but what you built into $page.