Page 1 of 1

die()ing without killing the *whole* script?

Posted: Sun Apr 01, 2007 9:34 am
by Mightywayne
Hey there. What my problem here is, is that whenever I have to give an error message on my pages, it does it fine of course, but then it kills the footer, and everything after the die point, for that matter.

So basically what I have is

Code: Select all

</td>
    </tr>
    <tr>
      <td height="25" align="center" colspan="2"><?php include("footer.html"); ?></td>
    </tr>
And some more stuff, after the die point. So it makes the error pages look weird because the footer is there to make the page look normal, so without it, the banner and stuff gets pushed down a little. Nothing too noticeable, but noticeable enough to make me want to stop it.

Posted: Sun Apr 01, 2007 9:42 am
by s.dot
You could do it in an if statement.

Code: Select all

if($there_is_an_error)
{
     echo 'Error Message';
     require 'footer.php';
     exit;
}

Posted: Sun Apr 01, 2007 9:46 am
by Mightywayne
Ah dude perfect. Thanks. :D

Posted: Sun Apr 01, 2007 4:46 pm
by Chris Corbyn
I thought from the title you were going to mean this, so I'll mention it anyway:

Code: Select all

include "one.php";
include "two.php";
include "three.php";
If two.php contains exit() or die() then three.php would never be loaded (of course). Interestingly, you can kind of do a "soft die" by placing the "return" keyword in the global context like so:

Code: Select all

<?php

$x = "blah";
$y = "bleh";

if ($x != $y) {
  return; //Exit *just* this particular include
}
It's a procedural programming nightmare though.