Server-side Versus Client-side
One of the keys to understanding PHP's role in the Web is to understand how the Web works at a fundamental level. This generally involves a basic understanding of HTTP, Hypertext Transfer Protocol. To examine the basic operation of the Web, consider a typical HTTP client, your Web browser. When you visit a URL such as http://example.org/, your browser sends an HTTP request to the web server at example.org. The simplest example of this request is as follows:
GET / HTTP/1.1 Host: example.org
The web server's responsibility is to respond to this request, preferably with the resource that is desired (the document root in this example). An example of a response is as follows:
HTTP/1.1 200 OK Content-Type: text/html Content-Length: 419 <html> <head><title>Example Web Page</title></head> <body> <p>You have reached this web page by typing "example.com", "example.net", or "example.org" into your web browser.</p> <p>These domain names are reserved for use in documentation and are not available for registration. See <a href="http://www.rfc-editor.org/rfc/rfc2606.txt">RFC 2606</a>, Section 3.</p> </body> </html>
As you should notice, the majority of this response is the actual content, the HTML. When your browser receives this response, it will render the web page (see Figure 3.1). Once a page is rendered, you can disconnect your computer from the Internet, and this won't cause a problem until your browser needs to send another HTTP request.
Where does PHP fit into this process? PHP's role is best explained as an aid to the web server while it is generating the HTTP response. Thus, by the time the web server sends the response, PHP's job is done. Its output is included in the response. Because PHP's activity takes place on the server, it is an example of a server-side technology.
Figure 3.1 A browser renders a web page.