2

ユーザーから電子メールでエラー レポートを受け取るのはイライラします。ほとんどのユーザーは開発者にバグ レポートを送信しないに違いありません。したがって、ユーザーが PHP エラー コードを取得した場合に、エラー レポートを電子メールで自動的に取得するように設定したいと考えています。

PHP または CodeIgniter でユーザー エラー レポートを取得する方法はありますか?

ありがとうございました。

4

3 に答える 3

1

次のようなことができます。

<?php  
// Our custom error handler  
function email_error_handler($number, $message, $file, $line, $vars)  
{  
    $email = " 
        <p>An error ($number) occurred on line 
        <strong>$line</strong> and in the <strong>file: $file.</strong> 
        <p> $message </p>";  
    $email .= "<pre>" . print_r($vars, 1) . "</pre>";  
    $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  
    // Email the error to someone...  
    error_log($email, 1, 'you@youremail.com', $headers);  
    // Make sure that you decide how to respond to errors (on the user's side)  
    // Either echo an error message, or kill the entire project. Up to you...  
    // The code below ensures that we only "die" if the error was more than  
    // just a NOTICE.  
    if ( ($number !== E_NOTICE) && ($number < 2048) ) {  
        die("There was an error. Please try again later.");  
    }  
}  
// We should use our custom function to handle errors.  
set_error_handler('email_error_handler'); 
// Trigger an error... (var doesn't exist)  
echo $somevarthatdoesnotexist;  

ソース

于 2012-12-30T14:11:23.930 に答える
0

エラー報告に関する codeigniter のドキュメントを見ることができます http://ellislab.com/codeigniter/user-guide/general/errors.html

error_reporting() 関数についての言及があります。おそらくそれをハッキングして、メールの操作を行うことができます。

于 2012-12-30T14:12:40.610 に答える
0

PHP は通常、Apache エラー ログ (Apache を使用している場合) に記録します。/var/log/httpd/error_log.

CodeIgniter のエラー ログは、config.php で有効になっている場合、デフォルトでapplication/log/date.php(日付は今日の日付) に記録するように設定されています。

必要に応じて、いずれか (または両方) のファイルの新しい変更を 1 時間ごとに電子メールで送信する cron を設定できます。set_error_handlerまたは、PHP の関数を使用して独自の PHP エラー ハンドラを作成することもできます。

編集: mbinette は、PHP のset_error_handler関数を使用する良い例を貼り付けました。1 つの注意点として、これは致命的な 500 エラーについては通知しません。エラー ログは通知します。

于 2012-12-30T14:12:18.707 に答える