Click to See Complete Forum and Search --> : $_GET versus $_POST


AJAX
01-20-2006, 05:02 PM
Which method should I be using for my forms? Why?

JDM71488
01-20-2006, 05:13 PM
$_GET will take the values out of the query string. (http://www.webdeveloper.com/forum/showthread.php?p=499470) so you can have links like that, or you can have method="get" on your forms. so for the example, your variable would be $_GET['p'].

$_POST will require method="post" on your forms and passes values "invisibly".

either one will work, but it depends on the application.

LiLcRaZyFuZzY
01-20-2006, 07:28 PM
most applications use a combination of both, for example this forum's application.
to display threads and profiles it uses GET..to post and edit it uses the POST method.

Actions are often passed through GET (because you can place them in a link)
By actions i mean, again for example when you edit a page on this forum, you see 'do=editpage' in the URL
But the values are passed through POST

NogDog
01-20-2006, 07:35 PM
For a form, I always use the post method. If you use get, it's possible that someone could bookmark a page that has your form submission data in it, which could then result in confusing, invalid, or buggy things happening if they go to that bookmark later.

bokeh
01-20-2006, 08:04 PM
$_GET should be used solely for data retrieval while $_POST should be used for everything else but should not be used for pure data retrieval. If there is a permanant change of state, e.g. send an email, upload a file or alter a database $_POST should be used.

$_GET: Look up a word in an online dictionary.
$POST: Order a new Mercedes Benz.

The $_POST method produces a warning if the user presses refresh. This is one reason why it should not be used for data retrieval. It would make the users desensitised to these types of warnings and casual about accepting them, meaning when the lorry turns up from Mercedes it would be dropping off two instead of one.

LiLcRaZyFuZzY
01-21-2006, 06:00 AM
$_GET: Look up a word in an online dictionary.
$POST: Order a new Mercedes Benz.

hahaha, good example bokeh! ;)

Yep, also you can see that google uses GET for their search engine. Most do. You probably never heard of those which don't :p

chazzy
01-21-2006, 11:03 AM
typically gets are used to get data out of something. post sends data into something.

see also bokeh's analogy.

felgall
01-21-2006, 03:18 PM
I think it depends more on what the action of the form is. If the action supports POST then use POST. If it doesn't support POST (eg. HTML page) then use GET.

web_dude
01-21-2006, 03:24 PM
another issue is size limit.
GET size limit is around 2000 characters. (different on every client)
POST limit is around 2 Mega.

bokeh
01-21-2006, 04:03 PM
another issue is size limit.
GET size limit is around 2000 characters. (different on every client)
POST limit is around 2 Mega.According to the RFC for HTTP 1.1 there is no size limit for either. The only condition is that servers should be able to understand any query string that they may server.I think it depends more on what the action of the form is. If the action supports POST then use POST. If it doesn't support POST (eg. HTML page) then use GET.I find this answer very strange. I take it by action you mean <form action="***"> i.e. the recieving script. The form and the script that handles the form are normally a pair so obviously the writer of the form and script is going to use the same method for both ends of the connection otherwise data transfer would be impossible.

I stand by my answer above: $_GET is for pure data retrival and $_POST is used for everything else. W3C (forms) (http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.1) seems to agree with this viewpoint.

chazzy
01-21-2006, 05:30 PM
According to the RFC for HTTP 1.1 there is no size limit for either. The only condition is that servers should be able to understand any query string that they may server.There is no limit in 1.1, but IE has a limit to its address bar length (and any address retrieval really) where it can't handle over 2000 characters.

I stand by my answer above: $_GET is for pure data retrival and $_POST is used for everything else. W3C (forms) (http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.1) seems to agree with this viewpoint.
Cheers!

bokeh
01-21-2006, 05:43 PM
IE has a limit to its address bar lengthWell it's not the only area it doesn't follow web standards. Have you seen how badly it renders the acid test (http://www.webstandards.org/act/acid2/test.html).

web_dude
01-22-2006, 03:42 PM
you're right saying that GET size limit is not according standard but it is because of bad implementation of some clients.
so what do you suggest?
To ignore clients that do not meet standards?
I can do that on my family web site, but not on a commercial site where you want to serve all users no matter what browsers they are using.
POST will save you some of the headache.
Of course you have plenty left :)

bokeh
01-22-2006, 03:51 PM
you're right saying that GET size limit is not according standard but it is because of bad implementation of some clients.
so what do you suggest?
To ignore clients that do not meet standards?
I can do that on my family web site, but not on a commercial site where you want to serve all users no matter what browsers they are using.
POST will save you some of the headache.
Of course you have plenty left :)Are you trying to suggest that a 2000 character query string might necessary for simple data retrival? Can you give an example?