Are they always strings or not? For example file_get_contents('php://input'); always reads the contents of the body of the POST request in the string.

  • And what other option do you expect? Boolean value? - Ipatiev

2 answers 2

Like most Internet protocols, HTTP is a text protocol. And all data is transmitted in it as strings.

If you want to transmit information about the type of variable, then you need to use the appropriate format, for example json.

If we talk about the $ _POST array, then, as cheops correctly writes in the next answer, in addition to strings, it may contain arrays, in accordance with the agreement on parsing variable names of a certain format.

    Generally speaking, you can send any data to the HTTP using the POST method, including binary, however, the PHP interpreter will only focus on the data formatted by the CGI agreement when building the $_POST superglobal array. Those. if the sequence is sent by the POST method

     hello=world&number=1 

    You will receive in $_POST two elements $_POST['hello'] and $_POST['number'] . Yes, their values ​​will always be strings, in this case "world" and "1". If you send a view sequence using the POST method

     14±3ды§ва`оЁыв3 

    That $_POST superglobal array will be empty, since the analyzer will not be able to select elements and values ​​from this sequence. However, you can read this line with file_get_contents('php://input') . Thus, you can send any data to the server, for example, binary or files. In PHP, a special $_FILES superglobal array is used for files, it also analyzes the body of a POST request and, if it detects a file download, fills the array with data. Php: // input is also resorted to if the Web server supports a method other than POST, for example PUT for which PHP does not have a separate super-global array.

    • Those. in other words, the $ _POST superglobal array always contains only strings. So? - user208916 pm
    • @Khipster, yes or arrays of strings, if the name takes the form name [] = dlfsdl & name [] = dfdsl - cheops
    • in fact, in the second example here is also a string. And "binary data" is already an interpretation. - Ipatiev
    • Actually, it is not written anywhere that these are not strings. Just in the second case, the $ _POST superglobal array will not be filled, since the string is not a CGI parameter set. - cheops