简体   繁体   中英

Block HTTP POST request

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 particular 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM