Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how post method of form actually work behind scene

Tags:

post

forms

php

get

I have used both get / post me and aware about the differences of both with regards to limitations / security and all.

Well,when we are using get method,we are getting data from query string and that is fine.

Now,for the post :

Let's say from one.php, we are passing variable name which is in form with method = "post" and we are getting it in two.php with $_POST['name'], where this name actually stored in between these 2 pages and from where it actually comes and one can able to get access it with $_POST?

Also, is there any chances for data being hacked / visible by / to anyone anyhow ?

Thanks!!

like image 902
CodeWithCoffee Avatar asked Mar 16 '15 12:03

CodeWithCoffee


People also ask

How does the POST method work?

POST is an HTTP method designed to send data to the server from an HTTP client. The HTTP POST method requests the web server accept the data enclosed in the body of the POST message. HTTP POST method is often used when submitting login or contact forms or uploading files and images to the server.

How data is passed in POST method?

The POST method transfers information via HTTP headers. The information is encoded as described in case of GET method and put into a header called QUERY_STRING. The POST method does not have any restriction on data size to be sent. The POST method can be used to send ASCII as well as binary data.

What happens after a form is submitted?

When a normal form submits, the page is reloaded with the response from the endpoint that the form submitted to. Everything about the current page that does not exist in a persistent medium (such as cookies, or Storage) is destroyed, and replaced with the new page.

How do you get information from a form that is submitted using the POST method?

The Correct Answer is " Request. Form". The Request. Form command is used to collect values in a form with method="post".


Video Answer


1 Answers

The value is stored in the request.

HTTP requests consist of a few key components. Mainly:

  • Address
  • Headers
  • Body

The key difference between a GET and a POST in this case is that a GET has no Body. So any data you want to include in a GET needs to be included on the Address. A POST, however, does have a Body. And it includes the key/value pairs for the values in that Body.

Take a look at your browser's debugging tools and examine the requests/responses when interacting with the server. For a POST request, you'll see that you can in fact inspect the values. (Which you may want to consider when you talk about knowing the "security" of these requests...)

The values aren't "stored" anywhere special. They work almost exactly like they do in a GET request. They're simply in another part of the request format.

like image 109
David Avatar answered Oct 14 '22 00:10

David