Web Programming with PHP

Most people think of a Web page as nothing more than a collection of HTML code. This is fine if you happen to be aWeb designer—but, as a PHP developer, your knowledge must run much deeper if you want to take full advantage of what the Web has to offer.

Fromthe point of view of theWeb server, the generation of a document starts with an HTTP request, in which the client requests access to a resource using one of a short list of methods. The client can also send a data payload (called request) along with its request—for example, if you are posting an HTTP form, the payload could consist of the form data, while if you are uploading a file, the payload would consist of the file itself. Once a request is received, the server decodes the data that it has received and passes it on to the PHP interpreter (clearly, we are assuming that the request was made for a PHP script—otherwise, the server can choose a different handler or, in
the case of static resources, such as images, output them directly).

Upon output, the server first writes a set of response headers to the clients; these can contain information useful to the client—such as the type of content being returned, or its encoding, as well as data needed to maintain the client and the server in a stateful exchange.

Forms and URLs
Most often, your script will interact with their clients using one of two HTTP methods:


Froma technical perspective, the main difference between these two methods is in the fact that the latter allows the client to send along a data payload, while the former only allows you to send data as part of the query string. This, of course, doesn’t mean that you can’t submit a form using GET—only that you will be somewhat limited in the size and type of data that you can send. For
example, you can only upload files using POST, and almost all browsers implement limitations on the length of the query string that confine the amount of data you can send out with a GET  operation.

Contrary to popular belief, POST is not an inherently more secure to submit forms than GET.
We explain this concept in greater detail in the Security Concepts whit PHP.

From an HTML perspective, the difference between GET and POST is limited to the action attribute of the <form> element:

<!–Form submitted with GET–>

<form action="index.php" method="GET">
   List: <input type="text" name="list" />
   Order by:
   <select name="orderby">
      <option value="name">Name</option>
      <option value="city">City</option>
      <option value="zip">ZIP Code</option>
   Sort order:
   <select name="direction">
      <option value="asc">Ascending</option>
      <option value="desc">Descending</option>

<!–Form submitted with POST–>

<form action="index.php" method="POST">
   <input type="hidden" name="login" value="1" />
   <input type="text" name="user" />
   <input type="password" name="pass" />

Next Topic

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *