Variables $_GET, $_POST & $_REQUEST (VGPR)

Hi guys, I'll share a little bit of my learning experience. When I was in semester 3, I still didn't understand the use of special variables such as PHP $ GET, $ POST, and $_REQUEST, because in principle they all carry data, it's just that I see each of them has a different way, so it's natural for me to wonder.

Well, the question is if they are created specifically for almost the same task, then how can I use them properly? please enlighten me, thank you.

$_GET

In PHP, string forms can be sent using 2 methods, and one of them is $_GET.

PHP Manual Explains:
The $_GET method is used to send Array type variables to related scripts via URL parameters, so that when the user presses the SUBMIT button, the script is executed, so that the details of the input information will be visible in the Address Bar, for example:

global variable get example

The $_GET method is used to send Array type variables to related scripts via URL parameters, so that when the user presses the SUBMIT button, the script is executed, so that the details of the inputted information will be visible in the Address Bar, for example:

Therefore, the $_GET method is highly not recommended for inputting sensitive data such as usernames and passwords.

Advantages of the $_GET method:

  • list text hereSaves the results of the submitted form
  • list text hereEase of testing servlets or JSP pages by simply entering a URL.

$_POST

In PHP, string forms can be sent using 2 methods, and one of them is $_POST.

PHP Manual Explains:\
The $_POST method is used to send Array type variables to related scripts via the HTTP POST method, meaning this method uses application/x-www-form-urlencoded or multipart/form-data, so that it handles requests acting as HTTP-Content.

When the user presses the SUBMIT button, the script is executed, and the reaction displayed in the browser can be seen in the following Address bar:

post variable example

So this method is most recommended for inputting sensitive data such as usernames and passwords.

Advantages of the $_POST method:

  • Allows users to send large amounts of data
  • Can send binary data, spaces, enter, tab, etc.
  • Keep away from users who try to peek at other people's personal data.

$_REQUEST

It is an associative array containing the $ GET, $ POST and $_CHOOKIE functions.

So the $_REQUEST function can retrieve data sent with the method:

  • GET
  • POST

Note:  An associative array is an array that does not use numbers as keys in each of its values. So if no key is specified for an element in the array, PHP will automatically provide a key in the form of a number.


Post a Comment

Previous Next

نموذج الاتصال