这已经被问了几次,一般的共识似乎是没有问题的参考直接使用$_POST
变量。事实上,通过使用该行
$code = $_POST['code']
你实际上为自己添加更多的代码和更多的工作。
但这完全取决于你如何使用$_POST
,无论哪种方式都很好。
更新
你不一定需要以使用$ _POST发布到网页数据见下文
echo '<pre>';
print_r($_POST); //return blank array as nothing has been posted to the page
echo '</pre>';
$_POST[] = 1; //even though no data has been posted we can use $_POST as a variable if we wish
echo '<pre>';
print_r($_POST); // This will print an array where $_POST[0] is equal to 1
echo '</pre>';
$_POST[0] = $_POST[0] + 1;
echo '<pre>';
print_r($_POST); // This will print an array where $_POST[0] is equal to 2 as we added one earlier
echo '</pre>';
所以在这里我们可以看到使用的$_POST
。在第三次印刷中,我们改变了$_POST[0]
的值。您也可以如您的代码所示,使$_POST
代表单个值而不是默认的数组。
因此,如果我们说
$_POST = 1+1;
echo '<pre>';
print_r($_POST); // This will print 2
echo '</pre>';
这将打印2.
就像你可以用$ _POST作为变量名的任何变量,虽然我不建议这一点,除非处理发布的数据。
这是您的代码吗? – putvande
'$ something = $ _POST;''稍后会让你能够使用'$ something ['code']',我发现它完全没用 –
你应该尝试遵循着名的做法,否则其他开发人员将难以遵循你的代码。 –