我正在尝试Firefox的内容安全策略。基本上,它是网页的一个特殊标题,告诉浏览器哪些资源是有效的。
当某个资源因违反策略而无效时,Firefox会以json格式向给定的URI发送报告。
这是一份典型的报告
array(1) {
["csp-report"]=>
array(4) {
["request"]=>
string(71) "GET http://example.com/?function=detail&id=565 HTTP/1.1"
["request-headers"]=>
string(494) "Host: example.com
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:2.0b10pre) Gecko/20110115 Firefox/4.0b10pre
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: es-ar,en-us;q=0.8,es;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Accept-Charset: UTF-8,*
Keep-Alive: 115
Connection: keep-alive
Referer: http://example.com/index.php?function=search&query=Pata+de+cambio+
Cookie: the cookie
"
["blocked-uri"]=>
string(4) "self"
["violated-directive"]=>
string(30) "inline script base restriction"
}
}内容类型为application/json;charset=UTF-8
现在。我期望这个在$_POST中作为REQUEST_METHOD==POST可用,但是post总是空的。我可以从php://input访问它,但问题是:为什么请求在$_POST中不可用?
我甚至不能使用filter_input而且$_REQUEST是空的.
发布于 2011-01-16 13:06:07
$_POST为您提供了表单变量,它们在页面中如下所示:
POST /some_path HTTP/1.1
myvar=something&secondvar=somethingelse但是您得到的不是有效的查询字符串。它可能看起来像这样:
POST /some_path HTTP/1.1
{'this':'is a JSON object','notice':'it\'s not a valid query string'}php://input以原始形式为您提供了标题之后的所有内容,所以在这种情况下,我认为这是获得您想要的内容的唯一方法。
发布于 2011-01-16 16:38:42
如果请求是以POST的形式发送的,那么它不一定被编码为普通的application/x-www-form-urlencoded或multipart/form-data。如果Firefox发送一个JSON主体,那么PHP不知道如何解码它。
你必须检查$_SERVER["HTTP_CONTENT_TYPE"]。如果它包含application/json,那么您一定要阅读php://stdin:
if (stripos($_SERVER["HTTP_CONTENT_TYPE"], "application/json")===0) {
$_POST = json_decode(file_get_contents("php://input"));
// or something like that发布于 2011-01-16 13:07:47
它可以是其他几种http请求类型(我现在知道有7种,还有几种占位符还在后面)。
我会打印$_REQUEST和$_SERVER,看看它是如何到达的。
https://stackoverflow.com/questions/4703906
复制相似问题