Difference between get and post. Using the GET and POST methods. More about HTTP
What they have in common is that they work the same way. There is technically no difference between them. But there are ideological differences.
I'll cover them in the context of PHP. Please note that the HTTP protocol is indirectly related to PHP because it was created for exchange html pages PHP just extends the capabilities of both.
GET request is used to receive data and POST to send. (As a reminder, they technically work the same way).
Therefore, in the context of PHP, based on this ideology, they did the following: 1. Superglobal arrays ($ _GET, $ _POST) are created by default every time you start PHP. 2. If there is a question mark (?) In the query string. Then everything that counts after him parameters GET request, they are presented in the format "key" = "value" and the ampersand character (&) is used as a separator Example: GET /index.php?name=Andrey&surname=Galkin this is a query string, there are 2 parameters. these parameters will end up in the $ _GET array. 3. $ _POST is filled in another way. the contents of this array are populated from the "request headers". That is, from a place hidden from view in an explicit form. All the routine of creating such headers is taken over by the browser. Although sometimes something is edited manually in the headings.
Most often, post request is used in forms (for submitting data).
For example we have a login form 2 fields login and password.
Let's imagine we are using the GET method. Then, when submitting the form, we will go to the following address /login.php?login=Andrey&password=123 agree that it is not at all safe to transfer such information in this way. Anyone can open your browser and starting to enter the site address, he can see your passwords and logins from history.
But if we specified with the POST method, then we would receive the following request: POST /login.php (login = Andrey & password = 123) what would be hidden in brackets and not saved in the browser in any way.
In general, summing up: GET is to get a specific page in a specific way (sorting, current blog page, search string, etc.). POST - for sending data that does not affect the display of the page, in the sense that this data only affects the result of the script execution (logins, passwords, credit card numbers, messages, etc.).
And one more good news, they can be combined, for example POST /index.php?page=login (login = Andrey & password = 123) I think I've already explained enough what will come of it and what parameters will get into which array.
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 address bar 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 into 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 words
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 put 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 come across 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:
The values
The value of the method attribute is case-insensitive. There are two methods - get and post.
Get This method is one of the most common and is designed to get the required information and transfer data in the address bar. Pairs "name = value" are appended in this case to the address after the question mark and separated by an ampersand (the & symbol). The convenience of using the get method is that the address with all parameters can be used repeatedly, saving it, for example, to browser bookmarks, and also changing the parameter values directly in the address bar. post The post method sends data to the server in a browser request. This allows more data to be sent than is available to the get method because it has a 4K limit. Large amounts of data are used in forums, postal services, database populations, file transfers, etc.
Required Attribute
Default value
HTML5 IE Cr Op Sa Fx
FORM tag, method attribute
Did not find an answer to your question? Look at here