How to include GET & POST data in PHP error log

Is there a way to have PHP errors for the log, or send me INCLUDING $_POST[] and $_GET[] and $_SERVER[] data error messages?

Now I get the PHP FATAL and WARNING and 404 NOT_FOUND , but it’s hard to debug some errors without knowing such things as user input and referrer.

thanks

+6
source share
4 answers
 error_log(print_r($_POST, true)); error_log(print_r($_GET, true)); 

Put this in a custom error handler and it will write both for you (the "true" parameter makes print_r display text instead of text).

You may need to increase the maximum line length in the error log with log_errors_max_len , since by default it is equal to 1024 characters and will truncate everything after that (it won 't split> 1024 char data across multiple lines).

+14
source

If you are using PHP 5, create a special exception class that will extend your own PHP exception class and add any data collection / logging methods that you like. This way you can easily combine the try {} catch() {} with Exceptions and have your own way of controlling how you want to log all the data.

+1
source

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

0
source

I worked on a telecom project that used CI to work with the Felx-based interface, we captured all possible error messages and wrote a shell about syslog functions and used it in our application, as a result we could log any data that we needed and the log was visible through viewing the system log :-)

-2
source

Source: https://habr.com/ru/post/894319/


All Articles