ad

Monday, 20 April 2015

GET and POST - The fundamentals

Please read HTTP the very basics before you start this tutorial.

I'm sure many of you are already familiar with HTML forms, if not, HTML form is a way to collect information from user. Most common HMTL form is login. You put in your username and your password and hit submit button.

Now you might be wondering, yeah that's fine I've filled the form and pushed the submit button, what happens next..? Well that's the reason I'm writing this tutorials, by the end of it you'll have a solid grasp of both methods, GET and POST, and also what happens after you've pressed the button.

Lets start from scratch, the moment you hit the submit button one of these two things happens, your data is checked, if it's valid, it's send to server - where it's then processed.

Lets start by GET request, here's a simple example.
Filled form, pressed submit. Client(browser/you) sends HTTP request to server, sending regular headers and request method. However this time, with request method it will send something else too, it's form data! When form data reaches server, it gets stored in $_GET variable

Client requesting URL and sending parameters(data) along with it.




Here's a simple example of POST request.
POST requests is simple too, instead of sending data with request URL it sends it with request body! and when server receives it, instead of $_GET it stores it into $_POST variable.
















Your data is always send in name value pair, like and separated by ampersand. When you're making get request anyone can see what you've typed in form from address bar. However if request is POST data is send in HTTP request body.

More about POST and GET requests.
http://php.net/manual/en/reserved.variables.post.php
http://php.net/manual/en/reserved.variables.get.php

No comments:

Post a Comment