3

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!

Xinrui Ma
  • 2,065
  • 5
  • 30
  • 52

2 Answers2

1

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.

thecodeparadox
  • 86,271
  • 21
  • 138
  • 164
1

$_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.

Suvash sarker
  • 3,140
  • 1
  • 18
  • 21