使用 Xdebug 调试远程服务器时,如何在 PhpStorm 中查看 $_POST 变量?

How can I see the $_POST variable in PhpStorm when debugging a remote server with Xdebug?

我对 PHP 比较陌生,所以如果我遗漏了一些明显的东西,请原谅我。

我已经在 Raspberry Pi 上设置了一个 Apache 服务器,并使用 PhpStorm 成功配置了 Xdebug,并且可以设置断点等。

我最初正在尝试一个基本的 html 表单,其中 Ajax POST 请求 运行 一个 PHP 文件来进行验证。当 PhpStorm 在 PHP 文件中设置的断点处中断时,它成功发送了请求,但是调试器中没有 $_POST 变量,只有 $_COOKIE$_SERVER.

如果有人有任何想法,我们将不胜感激。

JavaScript 在 html 文件中:

 $("#frmContact").on('submit',function (e) {
        e.preventDefault();
        $("#mail-status").hide();
        $('#send-message').hide();
        $('#loader-icon').show();
        $.ajax({
          url: "contact.php",
          type: "POST",
          dataType: 'json',
          data: {
            "name": $('input[name="name"]').val(),
            "email": $('input[name="email"]').val(),
            "selection": $('input[name="selection"]').val(),
            "content": $('textarea[name="formText"]').val()
          },
          success: function (response) {
            $("#mail-status").show();
            $('#loader-icon').hide();
            if (response.type == "error") {
              $('#send-message').show();
              $("#mail-status").attr("class", "error");
            } else if (response.type == "message") {
              $('#send-message').hide();
              $("#mail-status").attr("class", "success");
            }
            $("#mail-status").html(response.text);
          },
          error: function () {
          }
        });
  });

php.ini 文件(在 Raspberry Pi 上)

;XDebug
zend_extension=/usr/lib/php/20180731/xdebug.so
xdebug.remote_host=192.168.2.201
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.collect_params=4
xdebug.show_local_vars=on
xdebug.dump.SERVER=REQUEST_URI,DOCUMENT_ROOT,SCRIPT_FILENAME
xdebug.default_enable=1

PhpStorm 中的调试器图片:

请检查您的请求在浏览器的开发人员工具的“网络”选项卡中的显示方式。

我问这个的原因:您的请求可能没有正常通过或者它没有发送数据(这将解释为什么您在那里看不到 $_POST 变量:PhpStorm 可以隐藏这样的空全局变量(在 IDE 的调试工具窗口中检查选项)。

您的网络浏览器应该会告诉您究竟发送了什么以及它是否有任何重定向等(例如 POST 数据通常在 302 重定向时丢失,并且请求动词应在此处更改为 GET)。如果请求不包含 POST 数据,那么它一定是收集它的 JS 代码中的问题。