To submit a form application form data is the most common operations, often need to obtain various PHP backend data submitted by the user in the foreground form pages from the front page. Form data transfer mode has the following two methods, one of the POST () method, another is the GET () method. Which particular methodology used to obtain data by the method attribute <form> form specified below to explain the particular application of the two methods in a Web form. Marble platform manufacturers
Use POST () method to submit the form
When using the POST () method, simply <form> method attribute is set to POST the form to. POST () method does not rely on the URL, it will not appear in the address bar. POST () method can transmit data to the server, without limitation, all information submitted in the background transfers, the user in the browser can not see this process, security will be higher. Therefore, the POST () method is suitable for transmitting a security server (such as bank account number) or a large capacity data.
The following examples will use the POST () method sends the text box information to the server, the sample code is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Note: In the above code, form method property sheet specifies the POST () of the method of delivery, and by the action attribute specifies the data pages index.php. So, after clicking the "Submit" button to submit information to the server text box, the results are as follows:
Use GET () method to submit the form
In <form> default method form the GET method attribute () method. When submitting the form data using the GET () method, the data is appended to the URL and displayed, to be sent to the server as part of the URL. Cheng Hoon in the development process, since the URL attached to the transmission form data when the GET () method submitted, thus, the URL in the address bar will be shown to you "URL address + transfer parameter information of the user."
The GET parameter passing Format () method is as follows:
Wherein, url form in response to an address (e.g. 127.0.0.1/index.php), name1 is the name of the form element, value1 is the value of the form element. With between url and form elements "?" Separated, but with between multiple form elements "&" separated, each form element is the format name = value, fixed format and routines. You can keep in mind.
Note: To use the GET () method to submit the form, the length of the URL should be limited to less than 1MB characters. If the amount of data sent is too large, data will be truncated, leading to unexpected or failed processing results.
Create the following form to achieve a application GET () method to submit a user name and password, and displayed in the URL address bar. Add a text box, named User; add a password field named pwd; method attribute is set to form the GET () method, the sample code is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
After running this example, enter a user name and password in the text box, click on the "submit" button, the information in the text box will appear in the URL address bar, as shown in the following diagram:
Here you can obviously find, GET () method sets the parameters exposed in the address bar. Non-parametric privacy parameters passed if the user (e.g., id = 8), then the use of
The GET () method of data transfer is possible; privacy parameters passed if the user (e.g., password, etc.), data is transmitted using this method is insecure. The solution to this problem is to replace the default method attribute in a form of GET () method is POST () method.
These are the details to submit the form data in php POST () method and the GET () method,