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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

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

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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;
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post by Mightywayne »

Ah dude perfect. Thanks. :D
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
Post Reply