Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include GET & POST data in PHP error log

Tags:

php

Is there a way to have PHP log 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

like image 881
user366810 Avatar asked Aug 04 '11 19:08

user366810


1 Answers

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).

like image 112
Marc B Avatar answered Sep 20 '22 20:09

Marc B