search

Home  >  Q&A  >  body text

web - If you understand the PHP fastcgi protocol, you can’t get $_POST?

Implement an http server, and use fastcgi protocol to communicate with php-fpm when supporting php

To implement the get request, send QUERY_STRING and SCRIPT_FILENAME to php-fpm, and the server returns the result, which is normal here.

The post request is implemented by sending the content-length field and body content to the fastcgi server, and then the server returns the result. Like the following

Form code

<html>
<body>
<form action = "file.php" method  = "POST" >
    <input type="text" name="age" />
    <input type="submit"  />
</form>
</body>
</html>

php code

<?php
var_dump($_POST['age']);

Parameters sent

SCRIPT_FILENAME : /home/tan/Demo/studyHttpd/htdocs/file/file.php
REQUEST_METHOD : POST
QUERY_STRING : 
CONTENT_TYPE : application/x-www-form-urlencoded
CONTENT_LENGTH : 7

The body sent is , which is the content in the form

age=123

Why does php-fpm return NULL?

高洛峰高洛峰2780 days ago637

reply all(1)I'll reply

  • PHPz

    PHPz2017-05-18 10:50:36

    You print separately$_POST$_REQUEST
    that is:

    var_dump($_POST);
    var_dump($_REQUEST);

    reply
    0
  • Cancelreply