How to check if php://input is set?

后端 未结 4 2174
伪装坚强ぢ
伪装坚强ぢ 2021-02-19 10:54

I need to check if php://input exists/isset. Does it work with php isset() ? What is the proper way to check it?

4条回答
  •  没有蜡笔的小新
    2021-02-19 11:22

    Try to test it with file_get_contents() (for reading) + empty() or boolean conversion (for testing):

    From php.net:

    Note: Prior to PHP 5.6, a stream opened with php://input could only be read once; the stream did not support seek operations. However, depending on the SAPI implementation, it may be possible to open another php://input stream and restart reading. This is only possible if the request body data has been saved. Typically, this is the case for POST requests, but not other request methods, such as PUT or PROPFIND.

提交回复
热议问题