If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

Content of the POST field disappears

Started by sanjana, Oct 18, 2022, 03:57 AM

Previous topic - Next topic

sanjanaTopic starter

Greetings to all members of the community! On certain occasions, while transferring a POST to a script, I observe a loss of data. In this particular case, we have a simplified code that includes 'ent/enter.php' through '$tab = 'sr';'.

Here is the enter.php code that contains a form with a hidden input named 'tab' among others. Upon submission, the form is directed to '../ent/do_enter.php' where the PHP code checks if 'tab' is present in $_POST or not. If it's not present, the log file records an error message and the user is redirected to the homepage.

Do you have any idea what could be causing this issue? Any suggestions would be much appreciated. Thank you for your time!

$tab = 'sr';
include 'ent/enter.php';

enter.php :

...
echo
  "<form class='form_enter' name='form1' method='post'
          action='../ent/do_enter.php' >
   ...
    echo  "<input name='tab' type='hidden'  value=".$tab.">
  ...
      <input id='w_h' name='w_h' type='hidden'  value=''>     
      <input type='submit' name='enter' id='enter' value=' Войти ' class='exit_but bg1'
      onclick='get_w_h()' style= 'width: fit-content;margin-left:10px;'></div>
 </form>";

do_enter:

...
if (!isset($_POST['tab'])){
   $smess = 'No tab-a! ';
   foreach($_POST as $key => $value){
     $smess .= ' '.$key.' - '.$value.', ';
   }
   put_error_log($mess);
   header("Location:/");
   exit;
   // Occasionally I find myself here. In this case, the entire $_POST is empty.
}
  •  


mishraviplav7877

For instance, a GET request from an outside source or an empty POST request can trigger the loss of data. In certain instances, the post key "rattles" and sends data repeatedly. One possible solution could be to disable the button upon the first submission of data through blocking the post button on the "onclick".

To identify the root cause, it would help to log more information such as the request method, data in $_POST, $_SERVER, $_SESSION, etc. This way, it is easier to determine if it's a bot sending a form or a search robot accessing the page via a direct link. To prevent using the GET method to access do_enter.php, it is recommended to return a 405 error.

Based on the provided code, I assume that direct access to /ent/do_enter.php and /ent/enter.php may be possible, bypassing the main script.
  •  

RoyJones

I would examine a few potential root causes for the loss of data during the POST transfer to the script.

Firstly, I would verify the structure of the HTML form being generated in the `enter.php` file. It is essential to make sure that all form elements, including the hidden input 'tab', are correctly enclosed within the form tags and have the appropriate syntax for their attributes. In the provided code snippet, the value attribute assignment for the 'tab' input seems to lack quotes around the PHP variable $tab. This could inadvertently lead to issues if the $tab value contains spaces or special characters, potentially causing loss of data during the transfer.

Additionally, I would thoroughly examine the JavaScript function `get_w_h()` that is triggered upon form submission. Any actions performed by this function, such as modifying form data or interrupting the form submission process, could possibly contribute to unexpected data loss.

Furthermore, in the `do_enter.php` file, the code snippet that checks for the existence of the 'tab' key within the $_POST array seems appropriate. However, to gain more insight into the issue, I would log and inspect the entirety of the $_POST array when the 'tab' key is not present, in order to identify any other potential data loss or unexpected modifications to the form data.

I would also consider the possibility of environmental factors, such as server configurations or network issues, that could impact the data transfer process during the POST request.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...