开发者

Reading HTTP request headers to decide whether to proceed or not

I'm not awfully knowledgeable about HTTP, but my understanding is that an HTTP request consists of a bunch of headers and then the body.

Is it possible for PHP to receive the request headers, make a decision based on what's been received, and then either abort the request or continue to accept the bo开发者_如何学Gody?

This would be useful when receiving an uploaded file which is very large. I could therefore avoid the user wasting time in uploading a huge file only to discover the server won't accept it (file exists already). I know I could send a separate XHR request to do this, but I want to know if it's possible without that.

So, in short, can PHP cancel an HTTP Request after receiving only the headers?


The details of the HTTP connection are usually handled by the web server. So, it isn't possible to close the connection prematurely from PHP.

It would be possible to implement some kind of "filter" on the web server to scan for the headers you want to avoid, but this would likely involve creating a custom module, depending on your web server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜