7

I'm new in this forum and I'm learning PHP from this night.

I want to send a form but I do not know the difference between:

<form action="page2.php" method="GET">

and

<form action="page2.php" method="POST">

Anyone could help me please ?

Thanks.

Nic Wortel
  • 11,155
  • 6
  • 60
  • 79
Johny G
  • 79
  • 1
  • 1
  • 3
  • Maybe this might help you: http://www.cs.tut.fi/~jkorpela/forms/methods.html – juan.obando Mar 02 '13 at 03:18
  • @johny G if previous link doesn't help, check out http://www.w3schools.com/tags/ref_httpmethods.asp – Daniel Mar 02 '13 at 03:19
  • [Difference Between GET And POST Methods](http://www.jquery2dotnet.com/2014/03/difference-between-get-and-post-methods.html) – Sender Jun 11 '14 at 09:49

4 Answers4

24

GET:

  • Parameters remain in browser history because they are part of the URL
  • Can be bookmarked.
  • GET method should not be used when sending passwords or other sensitive information.
  • 7607 character maximum size.
  • Url example: page2.php?category=sport

POST:

  • Parameters are not saved in browser history.
  • Can not be bookmarked.
  • POST method used when sending passwords or other sensitive information.
  • 8 Mb max size for the POST method.
  • Url example: page2.php
F__M
  • 1,518
  • 1
  • 19
  • 34
  • 2
    Note that the max size for POST is not nessecarily 8MB, it can be configured on the server side. – Gerald Schneider Apr 28 '14 at 09:32
  • 1
    I find it odd that this answer got so many upvotes, people will actually find it and think there's a limit to POST. It also doesn't explain both methods properly. – N.B. Apr 28 '14 at 09:34
1

By convention HTTP GET is used for search forms while HTTP POST is used to change forms. A GET displays its information in the URL, publicly viewable, from which you can query the variables. A POST will not display its information. There is really no difference security wise.

LAT
  • 182
  • 1
  • 2
  • 6
0

If a GET request is used, the form parameters are encoded in the URL in what is called a query string.For example

www.someemailprovider.com/?login=joe@email.com&password=xxyz

A POST request, unlike a GET request, passes the form parameters in the body of the HTTP request, not in the URL.

Moreover GET is idempotent and POST is not that means If you call GET method on server nothing will be changed on server, but if you call POST then server will be changed may be a some additional data will be added in to the server, so GET is idempotent while POST is not.

Note

The main thing to keep in mind as a programmer is that defining your form to use the GET method does not protect against causing changes. You could use a GET request to do pretty much the same thing as a POST query. It’s just that browsers are generally coded to expect that POST requests will be used for things that will cause changes – like placing an order, or writing to a database, etc . GET requests should be used for pure queries that don’t affect anything on the server. So, one should always remember not to use GET requests for any action that would cause a change on the server – like ordering a big screen tv.

kaysush
  • 4,797
  • 3
  • 27
  • 47
-1

These are both HTTP request methods, not PHP exclusive.

$_GET is appended to end or URL. i.e. http://example.org/?foo=bar Access it in PHP with:

$foo = $_GET['foo'];

or $foo = $_REQUEST['foo'];

GET is used for information you don't mind people seeing, and can be manually typed into links and urls to get results.

$_POST is not visible in your URL, and generally is used after submitting a form. Access it in PHP with:

$foo = $_POST['foo'];

or $foo = $_REQUEST['foo'];

Read more about HTTP requests at http://www.w3schools.com/tags/ref_httpmethods.asp

yu_sha
  • 4,290
  • 22
  • 19
Josh Dean
  • 1,593
  • 2
  • 11
  • 17