_Unique_ Posted May 23, 2015 Share Posted May 23, 2015 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 Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted May 23, 2015 Share Posted May 23, 2015 (edited) 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 May 23, 2015 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
_Unique_ Posted May 24, 2015 Author Share Posted May 24, 2015 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 Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted May 24, 2015 Share Posted May 24, 2015 (edited) 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 May 24, 2015 by Ch0cu3r Quote Link to comment 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.