English 中文(简体)
PHP: 将POST转化为简单的变量?
原标题:PHP: translate POST into simple variables?
  • 时间:2012-05-14 18:52:32
  •  标签:
  • php
  • forms

我知道这是完全错误的,我没有写上这段话,我刚才不得不在我就新情况开展工作时这样做。 象GoDaddy这样的人向我们的账户做了一些更新,现在有一些事情没有做。 我已经把全球登记下来,许多事情已经恢复正常。 如今,这并不奏效。

有一个隐蔽的领域<input category=“hidden” name=“SUBMIT1”=“1”/>

对该领域进行了检查。

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

我知道,我可以很容易地通过这样做来解决这个问题。

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

问题在于,这是一个巨大的征兆,它将花一 time时间在任何地方这样做。 如果有某种方式或某种环境,我可以选择,这样,当提交表格时,如果提交表格,那么编号为:POST[WHATEVER ,也作为<代码>。

最佳回答

您可使用rel=“nofollow noreferer”>extract获取你描述的具体功能:

extract($_POST);

请在此指出可能的安全问题:用户可在_$_POST和“overwrite”中提供额外数据。 您可以通过第二个参数进入<代码>extract,以预防这些问题:

extract($_POST, EXTR_SKIP);

这将加速提取目前范围内已具备相应变量的<代码>_POST阵列中的任何领域。

问题回答

你可以尝试这样的事情:

$_POST =  array( SUBMIT1  =>  SUBMIT ONE ,  SUBMIT2  =>  SUBMIT  TWO );

foreach($_POST as $k => $v) {
    define(  . $k.   , $v);
}

echo SUBMIT1;  // and so on
foreach ($_POST  as $key => $value ) {

        if(is_array($value)){
            foreach ($value as $k => $v ) {
                $$k = $v ;

            }
        }else{

            $$key=$value;
        }

        echo $key ." : " .$value."<br>";
}




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签