Friday, November 23, 2007

PHP The $_POST variable

`PHP $_POST`

The $_POST variable is used to collect values from a form with method="post".

The $_POST variable is used to collect values from a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.

Example

HTML: test.html









When the user clicks the "Submit" button, the URL will not contain
any form data, and will look something like this:
 http://admincmd.blogspot.com/login.php

The "login.php" file can now use the $_POST variable to catch the form data (notice that the names of the form fields will automatically be the ID keys in the $_POST array):

PHP: login.php

< ?php
echo "Your name is ".$_POST["name"]
;

echo "Your password is ".$_POST["pass"];

?>

Why use $_POST?

  • Variables sent with HTTP POST are not shown in the URL
  • Variables have no length limit

However, because the variables are not displayed in the URL, it is not possible to bookmark the page.

No comments: