Jump to content

How to create a custom error page


_Unique_

Recommended Posts

Hello,

I am trying to create a custom error page using a function. So whenever there is an error, such as en error connecting to the database it shows the custom error page.

 

I believe wordpress has the same feature? Not sure, read it online somewhere when I tried to search how to do it.

 

I would rather use this function instead of using the die() function because I do not want the page to be reset, I want the content to disappear but the style to remain.

 

I have created a function for this to work but when the user gets the error page, you can also see the normal, ugly mysqi error, I have tried error_reporting(0) but it didn't hide the mysqli error message.

 

So, here is my code;

function errorDie($title = '', $error = 'An error has occured!') {
        echo 
            '<h3 class="title"><strong>Error: </strong>'.$title.'</h3><hr /><p>'.$error.'</p>';
        // Hide any errors
        error_reporting(0);
}

Thanks in advance,

 

Unique

Link to comment
Share on other sites

error_reporting only controls what type of errors to report. It does not handle whether to actually show the error message, which is handled by a setting called display_errors

 

Disabling display_errors will make PHP  issue a standard HTTP 500 status code when any errors occur. You can configure your HTTP server to issue a custom 500 error page (a static HTML page or it can be a PHP script).

Edited by Ch0cu3r
Link to comment
Share on other sites

error_reporting only controls what type of errors to report. It does not handle whether to actually show the error message, which is handled by a setting called display_errors

 

Disabling display_errors will make PHP  issue a standard HTTP 500 status code when any errors occur. You can configure your HTTP server to issue a custom 500 error page (a static HTML page or it can be a PHP script).

If I configure the HTTP server to display a 500 error page, how would I display a specific error to the user, for example, if there was no connection to the license server, then send the user to the 500 error page, where they will be told that there is no connection to the license server, probably because the connection is/was being tampered or the server is actually temporarily offline.

 

Thanks in advance,

 

Unique

Link to comment
Share on other sites

I should of also mentioned you can write your own error handler using set_error_handler. So if any PHP error occurred you can serve up a custom error page setting the error message dynamically.  You can also set your own error messages using trigger_error.

 

Where as the 500 Internal Server page would only be able to show a a generic error message - Although it is possible show dynamic error messages it just depends how your code handles errors. In which case you may as well write your own error handler.

Edited by Ch0cu3r
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.