How would one include a footer on a page if PHP has stopped executing during an error?

you fix the error..

depending on the kind of error you might try to catch it..

That's not what I mean. I mean general user-influenced errors like not entering valid details. I am using an exit function after displaying each error. Does that mean I have to put in include statement before every exit function?

i don't think im really getting what your trying to do, specifically why your using exit() but to do anything after calling exit() you could register a shutdown function:

function shutdown()
{
include 'footer.php';
}
register_shutdown_function('shutdown');

the "OOP way" would be using your __deconstruct() which will be called after exit().

i don't think im really getting what your trying to do, specifically why your using exit() but to do anything after calling exit() you could register a shutdown function:

function shutdown()
{
include 'footer.php';
}
register_shutdown_function('shutdown');

the "OOP way" would be using your __deconstruct() which will be called after exit().

Thanks that's just what I meant :)
If I register that shutdown function it will include the footer after every exit or die command?

I am using exit() after errors to stop the script from proceeding onto the next bit. Am I doing it wrong?

I never used a shutdown function but as the php manual says: "Terminates execution of the script. Shutdown functions and object destructors will always be executed even if exit() is called. " it should work as you want it to.

It is not wrong to call exit after an error but depending on the rest of your code it might not be the best way.

I never used a shutdown function but as the php manual says: "Terminates execution of the script. Shutdown functions and object destructors will always be executed even if exit() is called. " it should work as you want it to.

It is not wrong to call exit after an error but depending on the rest of your code it might not be the best way.

Don't want to trouble you any further but what other options are there to handle errors apart form using exit()?

Totally depends on your application but you described it as user-influenced errors so my guess is a if/else statement should be sufficient a alternative would be working with exceptions (again this all depends on the rest of your code).

add the footer line before each exit()
Example:

<html> <head></head> <body> <?php include("header.php"); ?> //header file externally designed
<?php
if(condition){
//some code
include("footer.php"); //if a external file for footer is designed
exit();
}
<?php include("footer.php"); ?> </body> </html>

since these footers comes under if/else statement, no chances of displaying them along with the main footer added befor the body end tag. Hope it works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.