Types Of Request Methods.

Types Of Request Methods.


GET METHOD

The predefined $_GET variable is used to collect values in a form with method="get".

Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send.

·         The GET method produces a long string that appears in your server logs, in the browser's Location: box.
·         The GET method is restricted to send up to 1024 characters only.
·         Never use GET method if you have password or other sensitive information to be sent to theserver.
·         GET can't be used to send binary data, like images or word documents, to the server.
·         The data sent by GET method can be accessed using QUERY_STRING environment variable.
·         The PHP provides $_GET associative array to access all the sent information using GET method.


Example:


Text Box: <form action="welcome.php" method="get">
Name: <input type="text" name="fname" /> Age: <input type="text" name="age" />
<input type="submit" />
</form>


When the user clicks the "Submit" button, the URL sent to the server could look something like this:


Text Box: http://www.test.com/welcome.php?fname=hemant&age=23

The "welcome.php" file can now use the $_GET variable to collect form data (the names of the form fields will automatically be the keys in the $_GET array):


Text Box: Welcome <?php echo $_GET["fname"]; ?>.<br /> You are <?php echo $_GET["age"]; ?> years old!


 POST METHOD


In PHP, the predefined $_POST variable is used to collect values in a form with method="post". The predefined $_POST variable is used to collect values from a form sent 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.



Text Box: <form action="welcome.php" method="post"> Name: <input type="text" name="fname" /> Age: <input type="text" name="age" />
<input type="submit" />
</form>

Example:

When the user clicks the "Submit" button, the URL sent to the server could look something like this:


Text Box: http://www.test.com/welcome.php

The "welcome.php" file can now use the $_POST variable to collect form data (the names of the form fields will automatically be the keys in the $_GET array):


Text Box: Welcome <?php echo $_POST["fname"]; ?>.<br /> You are <?php echo $_POST["age"]; ?> years old!



When to use 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.
However, because the variables are not displayed in the URL, it is not possible to bookmark the page.

No comments:

Post a Comment

=>Advanced Java Programming (J2EE)

1.  Syllabus 2. Unit Wise Question/Material 3. Paper 4. Previous Paper