Web Programming Although you will find it used in scenarios as diverse as quality control and point-of- sale systems, PHP was designed primarily as a Web-development language, and that remains its most common use to this day. In this chapter, we focus on the features of PHP that make it such a great choice for developing Web applications, as well as some Web-related topics that you should be familiar with in order to take the exam. Anatomy of a Web Page Most people think of a Web page as nothing more than a collection of HTML code. This is fine if you happen to be a Web designer—but, as a PHP developer, your knowl- edge must run much deeper if you want to take full advantage of what the Web has to offer. From the point of view of the Web 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 98 ” Web Programming 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 re- turned, or its encoding, as well as data needed to maintain the client and the server in a stateful exchange (we’ll explain this later). Forms and URLs Most often, your script will interact with their clients using one of two HTTP meth- ods: GET and POST. From a technical perspective, the main difference between these two methods is in the fact that the latter allows the client to send along a data pay- load, 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. i 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 chapter. From an HTML perspective, the difference between GET and POST is limited to the action attribute of the
element: List:
Order by:
Sort order: Web Programming ” 99