Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why should we use if( $_SERVER["REQUEST_METHOD"] == "POST") [duplicate]

Tags:

security

php

I am watching a video about PHP form submit, it mentions this method

if ($_SERVER["REQUEST_METHOD"] == "POST") {
/* code handle the form date */
}

I don't know why we should use that? Can someone explain for me? Thanks!

like image 626
Xinrui Ma Avatar asked Dec 18 '25 01:12

Xinrui Ma


2 Answers

$_SERVER['REQUEST_METHOD']

contains the request method. It is used to check request method.This variable also says if the request is a 'GET', 'HEAD', 'POST' or 'PUT' request.

like image 182
Suvash sarker Avatar answered Dec 20 '25 15:12

Suvash sarker


There are various methods of from submission like POST, GET, PUT, DELETE.

$_SERVER['REQUEST_METHOD'] holds the name of the method for a form submission. If you want to restrict your form processing only form POST type request, then you need to put that check.

like image 23
thecodeparadox Avatar answered Dec 20 '25 17:12

thecodeparadox