PHP:将POST转换为简单变量? [英] PHP: translate POST into simple variables?
问题描述
我知道这是完全错误的,我没有编写该应用程序,我只需要在开发新应用程序时使其运行即可.好像GoDaddy对我们的帐户进行了一些更新,所以现在有些事情不起作用了.我已经打开了寄存器全局变量,许多事情恢复了正常.现在,这不起作用...
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...
有一个隐藏字段<input type="hidden" name="SUBMIT1" value="1" />
有一个检查该字段
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.
}
问题是,这是一个巨大的应用程序,要花很多时间才能在任何地方都可以做到这一点.有什么方法或设置可以打开,以便在提交表单时$_POST['WHATEVER']
也可以用作$WHATEVER
?
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
?
推荐答案
您可以使用 extract
以获得您描述的确切功能:
You can use extract
to get the exact functionality you described:
extract($_POST);
请注意此处可能存在的安全问题:用户可以在$_POST
中发送额外的数据,并覆盖"代码中现有变量的值.您可以将第二个参数传递给extract
来防止出现这些问题:
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);
这将跳过提取$_POST
数组中在当前作用域中已经具有匹配变量的任何字段.
This will skip extracting any fields in the $_POST
array that already have matching variables in the current scope.
这篇关于PHP:将POST转换为简单变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!