Search code examples
phpphpstormxdebug

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


I'm relatively new to PHP so please forgive me if I'm missing something obvious.

I have set up an Apache server on a Raspberry Pi and successfully configured Xdebug with PhpStorm and can set breakpoints etc.

I am trying initially a basic html form with an Ajax POST request to run a PHP file to do validation. It successfully sends the request as PhpStorm breaks at a breakpoint set in the PHP file, however there is no $_POST variable in the debugger, only $_COOKIE and $_SERVER.

If anyone has any thoughts that would be much appreciated.

JavaScript in html file:

 $("#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 file (on 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

Image of the debugger in PhpStorm: PhpStorm debugger


Solution

  • Please check how your request appears in the Network tab of Developer Tools in your browser.

    The reason I'm asking this: it's possible that your request is not going through properly or it does not send the data with it (that will explain why you cannot see $_POST variable there: PhpStorm can hide such empty global variables (check the options for that in IDE's Debug toolwindow)).

    Your web browser should tell what exactly is getting sent and if it has any redirects etc (e.g. POST data is usually lost on 302 redirect and request verb should change to GET here). If request contains no POST data then it must be an issue in the JS code that collects it.