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!

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.