How can get form data using post method in php?

There exist two methods in PHP to collect data submitted in a FORM. PHP GET Method and PHP POST Method. 

In the PHP POST method, data from HTML FORM is submitted/collected using a super global variable $_POST. This method sends the encoded information embedded in the body of the HTTP request and hence the data is not visible in the page URL unlike the GET Method.

Advantages of Using POST Method

Some of the advantages of using the POST Method are:

  • POST Method can send data without any limitation on size.
  • Since the encoded information is embedded in the body of the HTTP request, it is not visible in the URL, hence the POST Method is preferred while sharing sensitive information.
  • It can also send binary data with the help of POST Method.

Disadvantages of Using POST Method

Some of the disadvantages of using this method are:

  • Since it does not embed data submitted by the POST Method in the URL, hence it is not possible to bookmark the page.
  • POST requests do not get stored in browser history.
  • POST requests are not cached.

Difference Between PHP GET and POST Method

Although both GET and POST methods are used to collect/submit form data, their methods exhibit some differences and are hence used according to need.

Some of the main differences between them are:

Method

GET

POST

Data Security

Not Secure

Secure

Data Limit 

2048 Characters

No Limit

Performance

Good

Slower

Data In URL

Visible

Not Visible

Data Types

Only String Data Types

String, binary, numeric, etc.

Cacheable

Yes

No

Example of POST Method Code

To understand how $_POST collects data, create a simple FORM with two fields - Name and Age, and collect and display that data using the POST Method.

    

      

Bài mới nhất

Chủ Đề