/    Sign up×
Community /Pin to ProfileBookmark

$_GET versus $_POST

Which method should I be using for my forms? Why?

to post a comment
PHP

13 Comments(s)

Copy linkTweet thisAlerts:
@JDM71488Jan 20.2006 — $_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.
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYJan 21.2006 — 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
Copy linkTweet thisAlerts:
@NogDogJan 21.2006 — 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.
Copy linkTweet thisAlerts:
@bokehJan 21.2006 — $_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.

[B]$_GET:[/B] Look up a word in an online dictionary.

[B]$POST:[/B] 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.
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYJan 21.2006 — 
[B]$_GET:[/B] Look up a word in an online dictionary.

[B]$POST:[/B] Order a new Mercedes Benz.
[/QUOTE]

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
Copy linkTweet thisAlerts:
@chazzyJan 21.2006 — typically gets are used to get data out of something. post sends data into something.

see also bokeh's analogy.
Copy linkTweet thisAlerts:
@felgallJan 21.2006 — 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.
Copy linkTweet thisAlerts:
@web_dudeJan 21.2006 — another issue is size limit.

GET size limit is around 2000 characters. (different on every client)

POST limit is around 2 Mega.
Copy linkTweet thisAlerts:
@bokehJan 21.2006 — another issue is size limit.

GET size limit is around 2000 characters. (different on every client)

POST limit is around 2 Mega.[/QUOTE]
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.[/QUOTE]I find this answer very strange. I take it by [I]action [/I] you mean <form [I]action[/I]="***"> 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. [URL=http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.1]W3C (forms) [/URL] seems to agree with this viewpoint.
Copy linkTweet thisAlerts:
@chazzyJan 21.2006 — 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.[/quote]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. [URL=http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.1]W3C (forms) [/URL] seems to agree with this viewpoint.[/QUOTE]
Cheers!
Copy linkTweet thisAlerts:
@bokehJan 21.2006 — IE has a limit to its address bar length[/QUOTE]Well it's not the only area it doesn't follow web standards. Have you seen how badly it renders the [URL=http://www.webstandards.org/act/acid2/test.html]acid test[/URL].
Copy linkTweet thisAlerts:
@web_dudeJan 22.2006 — 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 ?
Copy linkTweet thisAlerts:
@bokehJan 22.2006 — 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 ?[/QUOTE]
Are you trying to suggest that a 2000 character query string might necessary for simple data retrival? Can you give an example?
×

Success!

Help @AJAX spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...