Jump to content

Catching PHP errors


kid_drew

Recommended Posts

Hey guys,

So, if I have a PHP error that would normally dump to the screen, can I catch that error and instead divert the user to an error page that would say something like "We have encountered a server error.  Blah blah blah."  I'd really rather the user didn't see "Database connection failed" or "Call to member function on non-object".

 

-Drew

Link to comment
https://forums.phpfreaks.com/topic/45743-catching-php-errors/
Share on other sites

At the end of your query put:

 

or die("We have encountered a server error.  Blah blah blah.");

 

Here is an example of it used with a query:

mysql_query("UPDATE table SET col='$blah'")or die("We have encountered a server error.  Blah blah blah.");

Link to comment
https://forums.phpfreaks.com/topic/45743-catching-php-errors/#findComment-222209
Share on other sites

What I want is if the user encounters an error, I want to display an error page instead of the intended page, and I want that error page to still have the page layout of the rest of my pages.  If you create your own error handler function, can you call your formatting scripts from inside the function so that the page that displays instead still looks like it belongs to your site?  I.e.

 

function custom_error_handler($errno, $errstr, $errfile, $errline, $errcontext){

  require "header.php";

 

//  Insert error code here

 

  require "footer.php";

}

 

Or should I actually redirect them to an error page?  Maybe the try/catch method is best for what I'm trying to do.

 

You can override PHP's error reporting: http://us3.php.net/set_error_handler

 

Best,

 

Patrick

Link to comment
https://forums.phpfreaks.com/topic/45743-catching-php-errors/#findComment-222303
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.