Seaholme Posted July 25, 2012 Share Posted July 25, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/266208-how-to-die-without-cutting-off-the-footer/ Share on other sites More sharing options...
peipst9lker Posted July 25, 2012 Share Posted July 25, 2012 You should not use die() then Maybe you can use try-catch blocks to catch error's and give them out to the user. You have to always check are my data's correct, do my function calls return the right values etc. Quote Link to comment https://forums.phpfreaks.com/topic/266208-how-to-die-without-cutting-off-the-footer/#findComment-1364199 Share on other sites More sharing options...
KevinM1 Posted July 25, 2012 Share Posted July 25, 2012 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). Quote Link to comment https://forums.phpfreaks.com/topic/266208-how-to-die-without-cutting-off-the-footer/#findComment-1364200 Share on other sites More sharing options...
xyph Posted July 25, 2012 Share Posted July 25, 2012 As a quick hack, you could use register_shutdown_function to display the footer. Or you could use output buffering. Again, it's a hack, and better solutions are provided above. Quote Link to comment https://forums.phpfreaks.com/topic/266208-how-to-die-without-cutting-off-the-footer/#findComment-1364245 Share on other sites More sharing options...
PFMaBiSmAd Posted July 25, 2012 Share Posted July 25, 2012 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.) Quote Link to comment https://forums.phpfreaks.com/topic/266208-how-to-die-without-cutting-off-the-footer/#findComment-1364255 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.