PhpStorm $ _POST始终为空

时间:2016-02-09 10:52:00

标签: php post wamp phpstorm php-ini

$_POST似乎不起作用。我已经安装了PhpStorm 10.0.3,并使用WAMP服务器默认的php解释器。

在index.php中:

<form method='post' action='a.php'>
    <input type='text' name='user_f'>
    <input type='submit' name='send' value='Send'>
</form>

在a.php中:

var_dump($GLOBALS);

当我在表单中输入“asdf”时:

array (size=9)
      'HTTP_RAW_POST_DATA' => string 'user_f=asdf&send=Send' (length=22)
      '_GET' => 
        array (size=0)
          empty
      '_POST' => 
        array (size=0)
          empty
      '_COOKIE' => 
        array (size=0)
          empty
      '_FILES' => 
        array (size=0)
          empty
      '_ENV' => 
        array (size=0)
          empty
      '_REQUEST' => 
        array (size=0)

$_GET效果很好,但似乎解释器没有填充$_POST变量。

php.version:5.4.12(使用来自http://php.net/downloads.php的5.6.18和7个解释器的同样问题)

此版本的php.ini文件:(默认来自wamp)

其他像MySQL(3306)这样的端口在PhpStorm中运行良好。 (与phpmyadmin连接正常)

Xdebug端口:9000 PhpStorm内置服务器端口:63342

如果我使用默认localhost:8000

中的Netbeans IDE构建,一切都很好

我的笔记本电脑出现同样问题。

4 个答案:

答案 0 :(得分:2)

新的PhpStorm 2017.2.2 EAP版本(172.3968.23)解决了这个问题。

Bug WEB-17317 502发布数据时来自服务器的错误网关错误。

您可以下载here

完整版发行说明 链接=&GT; confluence.jetbrains.com/display/PhpStorm/PhpStorm+EAP+172.3968.23+Release+Notes

答案 1 :(得分:0)

将此解决方法粘贴到您网页的初始化中,以正常使用$_POST

<?php
//required when using PhpStorm's built-in webserver
//which always makes $_POST empty
//and must have .ini setting always_populate_raw_post_data = -1
//but will NOT work with enctype="multipart/form-data"
$raw_str = file_get_contents('php://input'); //eg. name1=val&name2=val
if($raw_str) {
    foreach (explode('&', $raw_str) as $pair) {
        $keyvalue = explode("=", $pair);
        $key = urldecode($keyvalue[0]);
        $value = urldecode($keyvalue[1]);
        $_POST[$key] = $value;
    }
}
?>

答案 2 :(得分:0)

与PHPSTORM无关,HTTP_RAW_POST_DATA可以存储来自请求的无法识别的数据,请试一试,内容类型:application / x-www-form-urlencoded add to Http headers;

答案 3 :(得分:-2)

尝试设置表单的enctype,如果没有它,可能不会填充$_POST数组,因为PHP只接收一串字段而不知道如何处理它:

<form method='post' action='a.php' enctype="multipart/form-data">
    <input type='text' name='user_f'>
    <input type='submit' name='send' value='Send'>
</form>
相关问题