简体   繁体   English

PHP POST无法正常工作:返回空数组

[英]PHP POST not working: Returning empty array

Look at the following PHP: 看下面的PHP:

<?php
var_dump($_POST);
?>

I am running this program using the following URL: 我正在使用以下URL运行该程序:

http://192.168.2.1:8888/a-s/bootstrap/php/test.php?lookup_word=parrot

And the result I am getting is this: 我得到的结果是:

array(0) { }

What sorcery is this? 这是什么法术? Why is it returning an empty array while I am feeding it at least one key-value pair? 为什么在给我至少一个键值对的同时返回空数组?

It's because your not getting the variable you defined in your URL. 这是因为您没有获得在URL中定义的变量。

you should do it like this: 您应该这样做:

var_dump($_GET['lookup_word']);

If you are looking for looking_word parameter in $_POST variable, you won't get it as its part of a GET request and will be available in $_GET . 如果要在$_POST变量中寻找looking_word参数,则不会将其作为GET请求的一部分,而将在$_GET可用。 If you want to make it general you can check $_REQUEST variable. 如果要使其通用,可以检查$_REQUEST变量。

<?php
var_dump($_REQUEST);
?>

As others mentioned, please have a look into the GET and POST concepts and $_GET , $_POST and $_REQUEST variables. 如其他人所述,请查看GET和POST概念以及$_GET$_POST$_REQUEST变量。

It's returning an empty array simply because the $_POST array in empty. 它只是因为$_POST数组为空而返回一个空数组。 You have not POSTED any data for $_POST to fetch. 您尚未发布任何数据以供$_POST提取。

Passing arguments via the URL sets them to $_GET not $_POST to set data to $_POST you have to POST data via an HTML form, curl etc 通过URL传递参数$_POST其设置为$_GET而不是$_POST来将数据设置为$_POST您必须通过HTML表单,curl等发布数据

try 尝试

var_dump($_GET);

Also please learn more about $_POST & $_GET 另外,请进一步了解$_POST$_GET

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM