php - Get form data on 500 error -


i'm attempting gather information when our sites encounter internal server error. have many applications never set proper error logging , when issue occurs our clients don't give best information work with. when 500 happens, collect data issue happened such as:

  • the page user on
  • any data associated page ($_get, $_post, etc)

i've set custom error pages on our server (iis 7) following config:

<?xml version="1.0" encoding="utf-8"?> <configuration>     <system.webserver>         <httperrors errormode="custom">             <remove statuscode="500" />             <error statuscode="500" path="/error.php?code=500" responsemode="executeurl" />         </httperrors>     </system.webserver> </configuration> 

and on page i'm var_dump-ing $_post , $_get see if in gets through error page, doesn't. goal on 500 error be:

  • gather data page/user @ time of error
  • send email support team issue containing gathered data

is there way collect data , have custom error page see it?

error.php:

switch($errorcode){     case '500':          var_dump($_request, $_post, $_get);          echo "internal server error";          break; } 

in cases $_post empty though submitted form error , $_get contains (which makes sense):

array(2) {   ["code"]=>   string(3) "500"   ["500;http://icom-sbs/test_php"]=>   string(0) "" } 

4/19 update

i played ideas, , main 1 being storing useful data in session variable. attempted store form data in session variable on test page gives error, never gets session. seems server detects error occur on page never executes code on page , executes error page.

if server started interpret php file , after 500 error occurred means fatal error happened in code. might anything, simple typo execution time limit reached.

the best , way catch fatal errors in php register_shutdown_function. should define on top of working file:

function handle_fatal() {     $error = error_get_last(); // php 5.2+     if($error !== null){         $error_landing_page = '[fatal] '.$error['message'].' in '.$error['file'].':'.$error['line'] . '<br/>get:<br/>' . print_r($_get, true) . '<br/>post:<br/>' . print_r($_post, true);         // mail here if need , include $_get, $_post variables - last state before error occurred         exit($error_landing_page);     } }  register_shutdown_function('handle_fatal'); 

simple test case:

// put handling function @ beginning function handle_fatal() {/*...*/} register_shutdown_function('handle_fatal');  // logic if($_get['page'] == 'dupa'){     $_post['subpage'] = 1; // more , more logic     $obj = new dupa(); // class not found exception } 

this handle_fatal example:

[fatal] class 'dupa' not found in /var/www/index.php:22 get: array ( [page] => dupa ) post: array ( [subpage] => 1 )  

after should know catching such errors not best idea , should careful it.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -