Just a reminder about security: neither POST nor GET are "secure". Any information is transmitted nearly in plan text within the IP packets.
For security of the transmitted information from client to server (and back) you MUST use transport layer security like e. g. SSL, HTTPS etc.
Tratando Formulários
Uma das características mais fortes do PHP é o jeito como ele trata formulários HTML. O conceito básico que é importante entender é que qualquer elemento de formulário em um formulário irá automaticamente ficar disponível para você usá-los em seus scripts PHP. Por favor leia a seção Variáveis externas do PHP para mais informações e exemplos de como usar formulários com PHP. Aqui vai um exemplo:
Exemplo #1 Um simples formulário HTML
<form action="acao.php" method="POST"> Seu nome <input type="text" name="nome" /> Sua idade: <input type="text" name="idade" /> <input type="submit"> </form>
Não há nada de especial neste formulário. É um formulário HTML comum sem nenhuma tag especial de qualquer tipo. Quando o usuário preencher este formulário e clicar no botão enviar, a página action.php é chamada. Neste arquivo nós teremos algo como este:
Exemplo #2 Imprimindo dados de nosso formulário
Oi <?php echo $_POST["nome"]; ?>.
Você tem <?php echo $_POST["idade"]; ?> anos.
Um exemplo de saída deste script seria:
Oi Thomas. Você tem 18 anos.
É óbvio o que este script faz. Não há nada de mais nele. As variáveis $_POST["nome"] e $_POST["idade"] são automaticamente criadas para você pelo PHP. Antigamente nós usávamos a auto-global $_SERVER, agora nós simplesmente usamos a auto-global $_POST que contém todos os dados vindos do POST. Se você usar o método GET então nossas informações residirão na auto-global $_GET. Você também pode usar a auto-global $_REQUEST se você não se importa com o tipo de dados que vêm do seu formulário. Esta auto-global contém uma mescla de GET, POST, COOKIE e FILE. Veja também a função import_request_variables().
Tratando Formulários
13-Apr-2012 09:05
11-Oct-2010 04:20
Also, don't ever use GET method in a form that capture passwords and other things that are meant to be hidden.
29-Mar-2008 06:27
I was so shocked that some servers have a problem regarding the Submit Type Name and gives a "Not Acceptable error" or Error 406.
Consider the example below :
<form action="blah.php" method="POST">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="Submit_btn" id="Submit_btn" value="Send">
</td>
</tr>
</table>
</form>
This very simple code triggers the "Not Acceptable Error" on
PHP Version 5.2.5 and Apache 1.3.41 (Unix) Server.
However to fix this below is the right code:
<form action="blah.php" method="POST">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="Submitbtn" id="Submit_btn" value="Send">
</td>
</tr>
</table>
</form>
The only problem that took me hours to find out is the "_" in the Submit Button.
Hope this help!
08-Nov-2006 06:02
As Seth mentions, when a user clicks reload or goes back with the browser button, data sent to the server, may be sent again (after a click on the ok button).
It might be wise, to let the server handle whatever there is to handle, and then redirect (a redirect is not visible in the history and thus not reachable via reload or "back".
It cannot be used in this exact example, but as Seth also mentions, this example should be using GET instead of POST
04-May-2005 09:18
[Editor's Note: Since "." is not legal variable name PHP will translate the dot to underscore, i.e. "name.x" will become "name_x"]
Be careful, when using and processing forms which contains
<input type="image">
tag. Do not use in your scripts this elements attributes `name` and `value`, because MSIE and Opera do not send them to server.
Both are sending `name.x` and `name.y` coordiante variables to a server, so better use them.
01-Dec-2003 10:55
According to the HTTP specification, you should use the POST method when you're using the form to change the state of something on the server end. For example, if a page has a form to allow users to add their own comments, like this page here, the form should use POST. If you click "Reload" or "Refresh" on a page that you reached through a POST, it's almost always an error -- you shouldn't be posting the same comment twice -- which is why these pages aren't bookmarked or cached.
You should use the GET method when your form is, well, getting something off the server and not actually changing anything. For example, the form for a search engine should use GET, since searching a Web site should not be changing anything that the client might care about, and bookmarking or caching the results of a search-engine query is just as useful as bookmarking or caching a static HTML page.

Algo Útil