开发者

How to include GET & POST data in PHP error log

Is there a way to have PHP l开发者_JAVA技巧og errors to a file or email me errors INCLUDING $_POST[] & $_GET[] and $_SERVER[] data?

Right now I get a log of PHP FATAL and WARNING errors and 404 NOT_FOUND errors but it's hard to debug some errors without knowing things like user input and the referrer.

Thanks


error_log(print_r($_POST, true));
error_log(print_r($_GET, true));

Put that into a custom error handler and it'll log both for you (the 'true' parameter makes print_r return text instead of outputting it).

You might need to boost the max line length in the error log with log_errors_max_len, as it defaults to 1024 chars and will truncate everything after that (it won't split >1024 char data across multiple lines).


If you are using PHP 5 create a custom exception class which will extend the native PHP Exception class and add whatever data collecting / logging methods you like. That way you could easily combine try {} catch() {} block with Exceptions and have your own way of controlling how you want to log all data.


I would recommend the error_log() function. I use that a lot to debug stuff in php. http://php.net/manual/en/function.error-log.php


I worked on a telecom project that used CI to handle a Felx based frontend, we hijacked all possible error reporting and wrote a wrapper on syslog functions and used it in our application, the result was we could log whatever data we wanted and the log was visible through system log viewer :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜