roldahayes Posted September 16, 2015 Share Posted September 16, 2015 (edited) Hi, I am having an issue with certain browsers not being able to receive the data from a $POST form. Could anyone advise a way of getting it to log what is being passed from the form and place it in a text file please? <html> <body onLoad="document.myForm.submit();"> <form action="https://secure2.epdq.co.uk/cgi-bin/CcxBarclaysEpdq.e" method="post" name="myForm"> <?php $user_agent = "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)";?> <? foreach($_POST as $i => $v) { ?> <input type="hidden" name="<?= $i ?>" value="<?= $v ?>" /> <? } ?> <input type="submit" value="If you are not automatically redirected, please click here" /> </form> </body> </html> Edited September 16, 2015 by roldahayes Quote Link to comment Share on other sites More sharing options...
Solution roldahayes Posted September 16, 2015 Author Solution Share Posted September 16, 2015 Solved, // Open LOG File$log = fopen ("formdata.log" , "a"); // For each value pair, output value to LOG$firstvalue=TRUE;foreach ($_POST as $key => $value) {if (!$firstvalue) { fwrite($log, ", "); } // If value is array (multiple select list)// Output array to LOG (elements sep by -)if (is_array($value) ) {$firstelement=TRUE;fwrite ($log, "\" ");foreach ($value as $element) {if (!$firstelement) {fwrite ($log, "-");$firstelement=FALSE;}fwrite ($log,$element); }} else { // Not array, output simple valuefwrite ($log, "\" $value ");$firstvalue=FALSE;} } // Line Feed and Close LOG fwrite ($log, "\n");fclose ($log); Thanks for looking Quote Link to comment Share on other sites More sharing options...
roldahayes Posted September 16, 2015 Author Share Posted September 16, 2015 Just one last question, how would I be able to get a line break after each output to make it more readable? I'm assuming I need "\n" somewhere in // For each value pair, output value to LOG $firstvalue=TRUE; foreach ($_POST as $key => $value) { if (!$firstvalue) { fwrite($log, ", ") ; } Quote Link to comment Share on other sites More sharing options...
roldahayes Posted September 16, 2015 Author Share Posted September 16, 2015 Sorry, worked it out again.... // For each value pair, output value to LOG $firstvalue=TRUE; foreach ($_POST as $key => $value) { if (!$firstvalue) { fwrite($log, "\n") ; } Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 16, 2015 Share Posted September 16, 2015 easier version - $file = 'formdata.log'; $data = date('Y-m-d H:i:s')." Agent:$_SERVER['HTTP_USER_AGENT']\nPost:".print_r($_POST,true)."\n"; file_put_contents($file,$data,FILE_APPEND); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.