differences betweenGET andPOST

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ali0482
Forum Newbie
Posts: 1
Joined: Thu Sep 30, 2010 12:18 am

differences betweenGET andPOST

Post by ali0482 »

What are the differences betweenGET andPOST methods in form submitting, give the case where we can use get and we can use post methods
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: differences betweenGET andPOST

Post by Christopher »

The practical difference is that GET includes the parameter values in the URL. Post puts the parameter values in the body of the request.

http://en.wikipedia.org/wiki/Hypertext_ ... r_Protocol
(#10850)
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: differences betweenGET andPOST

Post by DigitalMind »

use POST if you want your requests not to be cached
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: differences betweenGET andPOST

Post by AbraCadaver »

GET should only be used to retrieve or "get" data. Use POST to send data that will result in a consequence (delete record, insert record, send email, etc.).
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: differences betweenGET andPOST

Post by John Cartwright »

Moved to PHP-Code.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: differences betweenGET andPOST

Post by VladSun »

DigitalMind wrote:use POST if you want your requests not to be cached
Well while it's true, it's not always true :)
GET caching is easily solved by adding an unique parameter to the GET request - like this:
[text]http://domain.com?param1=value1&param2= ... value_here}[/text]

the {unique_value_here} is usually the current time in milliseconds (an ever incrementing value, thus it's unique).
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: differences betweenGET andPOST

Post by VladSun »

AbraCadaver wrote:GET should only be used to retrieve or "get" data. Use POST to send data that will result in a consequence (delete record, insert record, send email, etc.).
Just to elaborate - a GET request is vulnerable to CSRF thus a GET request should be used only and if only a pure "read" request is meant - i.e. no data changes required.

Another aspect of when to use a GET request can be found in RESTful services, though I'm not a big fan of it.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: differences betweenGET andPOST

Post by DigitalMind »

VladSun wrote:Well while it's true, it's not always true :)
GET caching is easily solved by adding an unique parameter to the GET request - like this:

Code: Select all

http://domain.com?param1=value1&param2=value2&....&__decache={unique_value_here}
the {unique_value_here} is usually the current time in milliseconds (an ever incrementing value, thus it's unique).
It's a very dirty solution and it doesn't mean your requests won't be cached. The cache will be cluttered up.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: differences betweenGET andPOST

Post by VladSun »

DigitalMind wrote:It's a very dirty solution and it doesn't mean your requests won't be cached. The cache will be cluttered up.
It's widely used by a lot of frameworks (ExtJS for sure) in order to solve cross browser caching issues. Just take a look.
Last edited by VladSun on Fri Oct 01, 2010 6:13 am, edited 2 times in total.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: differences betweenGET andPOST

Post by DigitalMind »

Nobody told it won't work. In my opinion it's bad approach.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: differences betweenGET andPOST

Post by VladSun »

DigitalMind wrote:Nobody told it won't work. In my opinion it's bad approach.
In my opinion IE is just a tool needed to install a browser ;)
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: differences betweenGET andPOST

Post by DigitalMind »

VladSun wrote:In my opinion IE is just a tool needed to install a browser ;)
Absolutely agree :D
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: differences betweenGET andPOST

Post by VladSun »

DigitalMind wrote:
VladSun wrote:In my opinion IE is just a tool needed to install a browser ;)
Absolutely agree :D
Ну договорились! :) [ OK, we've finally agreed :) ]
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: differences betweenGET andPOST

Post by DigitalMind »

Ага :) [Yup :)]
Post Reply