Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: translate POST into simple variables?

Tags:

forms

php

I know this is totally wrong, I didn't write the app, I just have to make it work while I work on the new one. Seems like GoDaddy made some updates to our account so now there are some things that don't work. I already turned register globals on and a lot of things went back to normal. Now, this doesn't work...

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

There is a check for that field

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

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

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

The problem is, this is a huge app and it's going to take a loooong time to do that everywhere. Is there a way or a setting I can turn on so that when a form is submitted $_POST['WHATEVER'] also works as $WHATEVER?

like image 554
leonel Avatar asked Feb 20 '23 12:02

leonel


1 Answers

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

extract($_POST);

Please note the possible safety issue here: a user could send extra data in $_POST and "overwrite" the values of existing variables in your code. You can pass a second parameter to extract to prevent these problems:

extract($_POST, EXTR_SKIP);

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

like image 72
Jon Gauthier Avatar answered Feb 26 '23 20:02

Jon Gauthier