Skip to content
Snippets Groups Projects
Commit 7c38fbea authored by Tim Steiner's avatar Tim Steiner
Browse files

Set up exception handling.

parent d62bf7f8
No related branches found
No related tags found
No related merge requests found
...@@ -2,20 +2,69 @@ ...@@ -2,20 +2,69 @@
/** /**
* ErrorController * ErrorController
* *
* @author * @author
* @version * @version
*/ */
require_once 'Zend/Controller/Action.php'; require_once 'Zend/Controller/Action.php';
class ErrorController extends Unl_Controller_Action { class ErrorController extends App_Controller_Action {
/**
* The default action - show the home page protected $_exceptions;
*/
public function errorAction() { public function errorAction() {
$exceptions = $this->getResponse()->getException(); $this->_exceptions = $this->getResponse()->getException();
throw $exceptions[0];
if ($_SERVER['REMOTE_ADDR'] == '129.93.39.17') {
header('Content-type: text/plain');
print_r($this->_exceptions);
exit;
}
$this->_sendEmail('tsteiner2@unl.edu');
$this->view->exceptions = $this->_exceptions;
} }
protected function _sendEmail($address, $moreAddresses = '...')
{
$mail = new Zend_Mail('utf-8');
$mail->setFrom('php@' . $_SERVER['SERVER_NAME'], $_SERVER['SERVER_NAME']);
$mail->setSubject('Exception Report');
foreach(func_get_args() as $address)
{
if(is_array($address)) {
$mail->addTo($address[0], $address[1]);
} else {
$mail->addTo($address);
}
}
$date = date('Y-m-d');
$time = date('H:i');
$body = "The following exception occured on $date at $time.\n\n"
. print_r($this->_exceptions, true)
. "\nRequest URI: " . $_SERVER['REQUEST_URI'] . "\n"
. "User Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\n"
. "User IP Address :" . $_SERVER['REMOTE_ADDR'] ."\n";
if(count($_GET) > 0) {
$body .= "\nGET variables: \n"
. print_r($_GET, true);
}
if(count($_POST) > 0) {
$body .= "\nPOST variables: \n"
. print_r($_POST, true);
}
/*
if(session_id() && ($_SESSION) > 0) {
$body .= "\nSESSION variables: \n"
. print_r($_SESSION, true);
}
*/
$mail->setBodyText($body);
$mail->send();
}
} }
<h1>Error</h1> <h1>Unfortunately an unexpected error has occured.</h1>
\ No newline at end of file <h2>Details have been mailed to the administrator for analysis.</h2>
<p>
The error message was: "<?php echo $this->exceptions[0]->getMessage(); ?>"
</p>
<p>
We appologize for the inconvience.
Please use the back button to return to your previous location
</p>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment