A common misconception is that there is a mixture of text and graphics flowing across a single HTTP request. After all, when you view a page, you see a single page containing such a mixture. It is important to understand that a standard web page containing text and graphics is created through a series of HTTP requests from the web browser, each answered by a response from the web server. Each response can contain one and only one type of data, and each image requires a separate HTTP request and web server response. Thus, if you see a page that contains some text and two images, you know that it has taken three HTTP requests and corresponding responses to construct this page.
Take this HTML page, for example:
<body>This page contains two images.
The series of requests sent by the web browser for this page looks something like this:
GET /page.html HTTP/1.0 GET /image1.png HTTP/1.0 GET /image2.png HTTP/1.0
The web server sends back a response to each of these requests. The Content-Type headers in these responses look like this:
Content-Type: text/html Content-Type: image/png Content-Type: image/png
To embed a PHP-generated image in an HTML page, pretend that the PHP script that generates the image is actually the image. Thus, if we have image1.php and image2.php scripts that create images, we can modify the previous HTML ...