Using Get or Post

I l @ ve RuBoard

The experienced reader will notice that we are missing one thing in our initial <FORM> tag, namely adding a METHOD attribute. This attribute tells the server how to transmit the data from the form to the handling script. I omitted it earlier because the topic merits its own discussion.

There are two choices you have with METHOD: GET or POST. I suspect that most HTML coders are not entirely clear on the distinction and when to use which. In truth, for the most part it won't make much difference ( especially as you first begin using them) as either will generally get you the results you need.

The difference between using GET versus POST is squarely in how the information is passed from the form to the processing script. The GET method will send all the gathered information along as part of the URL. The POST method transmits the information invisibly to the user . For example, upon submitting your form, if you use the GET method, the resulting URL will be something like:

 http://www.DMCinsights.com/php/   HandleForm.php?FirstName=   Larry&LastName=Ullman. 

Whereas using the POST method, the end user would only see

 http://www.DMCinsights.com/php/   HandleForm.php. 

When choosing which method to use, you may want to keep in mind these three factors: 1) with the GET method you are limited as to how much information can be passed; 2) the GET method publicly sends the input to the handling script (which means that, for example, a password which is entered in a form becomes viewable by anyone within eyesight of the Web browser, creating a larger security risk); and, 3) a page generated by a form that used the GET method can be bookmarked while one based upon POST cannot be.

In this text, I will use POST for handling forms, mostly to distinguish from a technique I will use where the GET method theory adds capabilities to your Web site (see Inputting Data Manually ). Either method will successfully pass along the data from the form and the final decision for which method you use should be based upon any mitigating factors in your form and whether or not the resulting page should be bookmark-able.

To add a method to your script:

  1. Open form.html in your text editor.

  2. Within the initial <FORM> tag, add METHOD=POST (line 6, Script 3.3).

  3. Save the script and upload it to your server.

  4. View the source of the page to make sure that all the required elements are present (Figure 3.2).

    Figure 3.2. By viewing the source of a page, you can see why something will work and why it won't. As with all programming, subtle changes can make all the difference.

    graphics/03fig02.gif

Script 3.3. It is up to you whether to use the GET or POST method as long as you remember to use one of them. With experience you will determine when it makes sense to use one rather than the other, but it is more of a finesse than function issue.

graphics/03sc03.jpg

I l @ ve RuBoard


PHP for the World Wide Web (Visual QuickStart Guide)
PHP for the World Wide Web (Visual QuickStart Guide)
ISBN: 0201727870
EAN: 2147483647
Year: 2001
Pages: 116
Authors: Larry Ullman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net