What is get. Making POST and GET requests
This post is intended to explain the principles of transferring data on the Internet using two main methods: GET and POST. I wrote it as a supplement to the instructions for the shift work generator for those who are hardly interested in the details ☺.
Go to the following address (this is for visual explanation): http://calendarin.net/calendar.php?year=2016 Pay attention to the address bar of the browser: calendarin.net/calendar.php ? year = 2016 The main file is named, followed by a question mark (?) And a "year" parameter with a value of "2016". So, all that follows the question mark is a GET request. It's simple. To pass more than one parameter, but several, then they need to be separated by an ampersand (&). Example: calendarin.net/calendar.php ? year = 2016 & display = work-days-and-days-off
The main file is still named, followed by a question mark (?), Then - the parameter "year" with the value "2016", then - the ampersand (&), then - the parameter "display" with the value "work-days-and-days -off ".
GET parameters can be changed directly in the address bar of the browser. For example, changing the value "2016" to "2017" and pressing the key, you will go to the calendar for 2017.
This is the transmission of data in a hidden way (the page address does not change); that is, you can see what was transmitted only with the help of a program (script). For example, in the following tool for counting characters in a text, the source data is transmitted using the POST method: http://usefulonlinetools.com/free/character-counter.php
If you have any questions, comments and my E-mail at your service.
In addition to the GET method, which we discussed in the previous post, there is another method for sending a request via the HTTP protocol - the POST method. The POST method is also very often used in practice.
If, in order to access the server using the GET method, it was enough for us to type the request into the URL, then in the POST method everything works according to a different principle.
In order to fulfill this kind of request, we need to click on the button with the type = "submit" attribute, which is located on the web page. Note that this button is located in the element
If the user enters any text in the text field and clicks on the "Submit" button, then the text variable with the value of the content entered by the user will be sent to the server.
POST and GET requests in simple terms
This variable will be sent by the POST method.
If you write in the form like this:
The form has attributes, I will list the most common ones:
Let's create a form:
As a handler file, I put the file test.php as it is in it that I write examples for you. I set the method of sending post as these methods are used in 99.9% of cases. I also gave our form a name - form
Now let's dive into the world of form elements. The first thing you need to understand is that almost all elements are tags. the only difference is in the attribute type at these tags. Let me list the form elements used:
I'm sure you have seen such fields more than once, so here, as they say: "no comments"
Now let's put together a short training questionnaire that we will work with next. Our task is to compose a small questionnaire that will tell us the name of the person who filled out, gender, what country he is from, his favorite color and a text field where the user can add something about himself. That's what I did: