如何检查php://input是否设置? [英] How to check if php://input is set?
问题描述
我需要检查php://input
是否存在/设置.它可以与php isset()
一起使用吗?正确的检查方法是什么?
I need to check if php://input
exists/isset. Does it work with php isset()
? What is the proper way to check it?
推荐答案
尝试使用 file_get_contents()
对其进行测试(用于阅读)+ empty()
或
Try to test it with file_get_contents()
(for reading) + empty()
or boolean conversion (for testing):
<?php
$input = file_get_contents('php://input');
if ($input) {
// exists
} else {
// not exists
}
来自 php.net :
注意: 在PHP 5.6之前,用
php://input
打开的流只能读取一次;该流不支持搜索操作.但是,根据SAPI的实现,有可能打开另一个php://input流并重新开始读取.仅在请求正文数据已保存的情况下才有可能.通常,POST请求就是这种情况,而其他请求方法(例如PUT或PROPFIND)则不是这种情况.
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.
这篇关于如何检查php://input是否设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!