In the internet world, the protocol that is commonly used is the HTTP protocol, this protocol has several request methods, including GET and POST.
PHP also provides the means to interact with these two request methods: (1) storing GET and POST data and (2) sending GET and POST data.
- $_GET in PHP
The $_GET variable in PHP is an associative array. This variable has the same shape as a variable in general, the difference is that $_GET is a global variable so it can be accessed anywhere.
Because the shape is the same as the others, we can manipulate this variable as we manipulate other array variables, for example by adding its value: $_GET[‘status’] = ‘active’ or deleting it unset($_GET[‘name’])
- Advantages and Disadvantages of $_GET
Excess :
Simple, and easy to edit data, for example to go to page 5 of a website, we just change the url.
Pages can be bookmarked and stored in the browser history so that they are easy to access again.
Can return to the previous page easily (by clicking the Back button in the browser).
Can be refreshed easily.
Can be distributed / shared.
Deficiency :
The data length is limited to only 2kb – 8kb (depending on the browser), if it exceeds this limit an error message will appear 414 Request-URI Too Long, so it cannot be used to send large amounts of data.
Can only send text type data, other types such as: images, zip files, etc. cannot be sent.
Since data is sent via URL, it is easily exposed.
- $_POST in PHP
Just like $_GET, the $_POST variable is also in the form of an associative array and is global, which means it can be accessed anywhere, besides that it can also be manipulated like other array variables.
We often encounter the use of the POST method, especially when sending data using html forms. For example: continuing the previous example, in the registration.php file we change the method in the form section from get to post and can only be seen by the admin.
- Advantages and Disadvantages of $_POST
Advantages :
It is safer than the GET method because the data sent is not visible, and the parameters sent are not stored in the browser history/browser log.
Can send large amounts of data.
Can send various types of data such as images, files, etc., not necessarily text.
- Disadvantages
Data is not saved in browser history.
Data cannot be bookmarked.
Because it is considered sensitive data, then when we refresh the browser, a confirmation of data retransmission will appear, as well as when we press the back button.
- Conclusion and Closing
In making a good website, of course we need register input, login, suggestions, and much more to improve our website to make it better that’s where we can use $_GET and $_POST.
The need for digital IT is needed in daily activities, Bead IT Consultant is the right choice as your partner, visit our website by clicking this link: www.beadgroup.com