Search code examples
phphtmlhandlerstack-trace

Showing twice html


So I'm making an error handling for my site. I want to be able to activate the error handler by using

include_once("errorhandler.php");

so far it works great, it display the error if an error occurs, however I'm facing another problem. I've made a php file called "test.php", that looks like this:

<?php
include("errorhandler.php");
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <h1>My awesome page :D</h1>
        <?php
            mysql_connect("test","test");
            opendir("test");
        ?>
    </body>
</html>

Now the issue is that, the error is display but the header is also shown, since it gets to execute that part, before the script crashes and starts the error handler.

It makes the page look like this: Image of the error

Basically, I need the error handler to clear everything before it writes the Html.

I've tried using <script> document.write('');</script>

In the start of my error handling method, with no luck.

So now I'm stuck with this, any ideas on how to solve this?


Solution

  • Used ob_clean(); In the start of the error handler, so when it occured it would clean the page!