Jump to content

How to die without cutting off the footer?


Seaholme

Recommended Posts

I apologise in advance if this is a simple question, but essentially I have a forum with the following code:

 

if($a_answer == '')
die("You must enter in a reply!");

 

And my problem is that when nobody enters a reply and it does default to the die option, that nothing subsequent to the die command shows up on the page below it, including the footer of the website, which leaves the whole thing looking very unprofessional. Is there a way to add the website footer into the 'die' command? (I've tried and failed). Or should I be using a different command from die that's more suited to what I'm trying to achieve? The footer is attached to the page via an include command.

 

Any suggestions gratefully received!

Using die isn't usually a good idea in a production site because of the issue you're experiencing.  die() is the nuclear, stop everything now way of dealing with an error, and, as you can see, isn't very graceful.  Well-formed PHP scripts do all of their processing upfront, before attempting to output HTML.  This allows one to redirect to an error page of some sort immediately, if the error is critical, or otherwise collect the errors for display on the current page.

 

It's odd that a forum would use die() simply because a form field wasn't filled out.  That's incredibly overkill.  Instead of shutting everything down, merely echo the error.  That's what this forum does (try replying without actually writing anything).

How to die without cutting off the footer?

 

That's backwards. Cutting off a foot(er), without adequate medical attention, usually results in dieing.

 

Hay, what did you expect. Telling your code to die is an immediate and terminal condition (there's no php CPR statement.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.