Sʜɩvʌɱ
Sʜɩvʌɱ

Reputation: 1

Suitable places for super globals

I was searching where to use $_POST, $_REQUEST, $_GET but I only saw the differences among them.

The only I got to know that

  1. $_REQUEST contains remaining two.
  2. $_GET is used for fetching.
  3. $_POST is used for inserting, updating, deleting.

I want to know these things

  1. I want to know that when $_REQUEST can perform all the tasks then why there was need to create remaining two.

  2. Explain the situations where we choose either $_REQUEST and where we choose $_GET or $_POST and not $_REQUEST

And what will the loss if we use use $_REQUEST instead of $_GET or $_POST

Upvotes: 0

Views: 31

Answers (1)

some-non-descript-user
some-non-descript-user

Reputation: 616

If it doesn't matter to you wether data comes in via post or via get you can use $_REQUEST. If you know which of the two will be the method data will be provided to your server-side code, use the appropriate super global. E.g. it's extremely easy to tamper with GET parameters, so you might want to avoid this method in certain parts of your application for security reasons. If you use POST you shouldn't read $_REQUEST, because there's a risk someone might add additional parameters in the URL via GET.

Upvotes: 1

Related Questions