Post () method and get () method for submitting form data in PHP

Source: Internet
Author: User
Submitting get form data is the most commonly used action in a form application, and often requires PHP background to get the various data submitted by the user in the foreground form page from the foreground page. form data is passed in the following two ways, one for the post () method and the other for the Get () method. The specific method used to obtain the data is specified by the methods property of the <form> form, and the following describes the application of the two methods in the Web form.

Use the post () method to submit the form

When using the post () method, you only need to set the attribute method in the <form> form to post. The POST () method does not depend on the URL and is not displayed in the Address bar. The POST () method can pass the data to the server without restriction, all the submitted information is transferred in the background, the user cannot see the process in the browser side, the security will be higher. So the post () method is more suitable for sending a confidential (such as bank account) or large-capacity data to the server.

The following instance sends the text box information to the server using the post () method, as shown in the following example code:

<! DOCTYPE html>

Note: In the above code, the method property of the form form specifies how the POST () method is passed, and the data page is specified with the Action property index.php. Therefore, when you click the "Submit" button, you can submit the text box information to the server, the results are as follows:

Submit a form using the Get () method

The GET () method defaults to the method property in the <form> form. When submitting form data using the Get () method, the data is appended to the URL and displayed as part of the URL to be sent to the server side. During the Cheng development process, the form data submitted by the Get () method is appended to the URL when it is sent, so the URL address bar will display the following content "URL + user-passed parameter information".

The pass format for the GET () method is as follows:

Where the URL is the response address of the form (such as 127.0.0.1/index.php), Name1 is the name of the form element, and value1 is the value of the form element. Between the URL and the form element, use "? "Separated by" & "between multiple form elements, the format of each form element is name=value, invariant formatting and routines. Keep it in mind.

Note: To submit a form using the Get () method, the URL length should be limited to 1MB characters. If the amount of data sent is too large, the data will be truncated, leading to unexpected or failed processing results.

Create a form below to implement the Apply GET () method to submit a user name and password and display it in the URL address bar. Add a text box named user, add a password field, name PWD, and set the method property of the form to the GET () methods, as shown in the sample code:

<! DOCTYPE html>

Run this instance, enter the user name and password in the text box, click the "Submit" button, the information in the text box will be displayed in the URL address bar, as shown in the following figure:

It is quite obvious here that the GET () method exposes the parameters to the address bar. If the parameters passed by the user are non-confidential parameters (such as id=8), use the

The GET () method is possible to pass data, and it is not safe to pass data using this method if the user passes the privacy parameters (such as passwords, etc.). The solution to this problem is to replace the method property's default Get () method in the form with The post () method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.