开发者

Block HTTP POST request

开发者 https://www.devze.com 2023-02-11 04:42 出处:网络
I am seeing an usually high number of HTTP POST requests on my website, and I was wondering: Is there any way to block a POST request on a particul开发者_JAVA百科ar php page by making modifications to

I am seeing an usually high number of HTTP POST requests on my website, and I was wondering: Is there any way to block a POST request on a particul开发者_JAVA百科ar php page by making modifications to either the php file or .htaccess file? Thanks in advance!


In native PHP it's as simple as checking one $_SERVER variable:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    die('Post is not allowed');
}

Within .htaccess, use a combination of <Files> and <limit>:

<Files myfile.php>
    <Limit POST> 
        Order deny,allow 
        Deny from all 
    </Limit>
</files>


if ($_SERVER['REQUEST_METHOD']) == 'POST') die();


POST /test HTTP/1.1 Host: foo.example Content-Type: application/x-www-form-urlencoded Content-Length: 27

field1=value1&field2=value2

0

精彩评论

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

关注公众号