PHP: translate POST to simple variables?

I know that this is completely wrong, I did not write the application, I just need to get it to work while I'm working on a new one. It seems that GoDaddy has made some updates to our account, so now there are some things that do not work. I have already enabled register globals, and many things have returned to normal. Now this does not work ...

There is a hidden field <input type="hidden" name="SUBMIT1" value="1" />

There is a check for this field.

 if($SUBMIT1) { // this part never gets executed. } 

I know that I can easily fix this by doing it instead ...

 if($_POST['SUBMIT1']) { // this part never gets executed. } 

The problem is that this is a huge application, and for this you need to take the time to do it everywhere. Is there a way or setting that I can enable so that when sending the form $_POST['WHATEVER'] also works like $WHATEVER ?

+4
source share
3 answers

You can use extract to get the exact functionality that you described:

 extract($_POST); 

Pay attention to a possible security problem here: the user can send additional data to $_POST and "overwrite" the values โ€‹โ€‹of existing variables in your code. You can pass a second extract parameter to prevent these problems:

 extract($_POST, EXTR_SKIP); 

This will skip retrieving any fields in the $_POST array that already have the corresponding variables in the current scope.

+8
source

you can try something like this:

 $_POST = array('SUBMIT1' => 'SUBMIT ONE', 'SUBMIT2' => 'SUBMIT TWO'); foreach($_POST as $k => $v) { define(''. $k. '', $v); } echo SUBMIT1; // and so on 
0
source
 foreach ($_POST as $key => $value ) { if(is_array($value)){ foreach ($value as $k => $v ) { $$k = $v ; } }else{ $$key=$value; } echo $key ." : " .$value."<br>"; } 
0
source

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


All Articles