8. HTTP and Server-Side Processing

  1. HTTP/1.0 Overview
  2. HTTP Interaction
  3. HTTP/1.1 Persistent Connections
  4. Pipelining
  5. HTTP Client Requests
  6. HTTP Server Responses
  7. Some request and response headers
  8. Example of request and response
  9. Example using HTML form
  10. HTML for form
  11. HTML form processing
  12. Server-side processing technologies
  13. PHP
  14. PHP code for www-inventor.php
  15. Processing XML with PHP (1)
  16. Processing XML with PHP (2)
  17. Retrieving JSON
  18. REST
  19. PHP and JSON
  20. PHP code for Nobel Prizes (1)
  21. PHP code for Nobel Prizes (2)
  22. PHP code for Nobel Prizes (3)
  23. Links to more information

8.1. HTTP/1.0 Overview

8.2. HTTP Interaction

8.3. HTTP/1.1 Persistent Connections

HTTP persistent connections

8.4. Pipelining

HTTP pipelining

8.5. HTTP Client Requests

8.6. HTTP Server Responses

8.7. Some request and response headers

8.8. Example of request and response

Machine responses are this colour below:

Peter-Woods-MacBook-Pro:~ ptw$ telnet www.dcs.bbk.ac.uk 80
Connected to www.dcs.bbk.ac.uk.
Escape character is '^]'.
GET / HTTP/1.0

HTTP/1.1 200 OK
Date: Fri, 18 Nov 2011 17:44:06 GMT
Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/0.9.8o DAV/2 SVN/1.6.5 mod_fcgid/2.3.6 mod_perl/2.0.4 Perl/v5.8.4
Connection: close
Content-Type: text/html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<title>Computer Science and Information Systems Birkbeck University of London</title>



Connection closed by foreign host.
Peter-Woods-MacBook-Pro:~ ptw$

8.9. Example using HTML form

8.10. HTML for form

<form action="http://titan.dcs.bbk.ac.uk/~ptw/teaching/IWT/server/www-inventor.php"
  <label for="www-inventor">Who invented the WWW (surname only)?</label>
  <input type="text" id="www-inventor" name="inventor" />
  <input type="submit" value="Submit answer" />
  <input type="reset" value="Erase answer" />

8.11. HTML form processing

8.12. Server-side processing technologies

8.13. PHP

8.14. PHP code for www-inventor.php

<head><title>WWW Inventor</title></head>
if ($_GET['inventor'] == "Berners-Lee")
   echo "Congratulations, you answered correctly.";
   echo "Sorry, the correct answer is Berners-Lee.";

8.15. Processing XML with PHP (1)

8.16. Processing XML with PHP (2)

8.17. Retrieving JSON

8.18. REST

8.19. PHP and JSON

8.20. PHP code for Nobel Prizes (1)

<h1>Nobel Prize Winners</h1>
  $year = $_GET['year'];
  if ($year >= 1901 && $year <= 2017) {
    $url = 'http://api.nobelprize.org/v1/prize.json?year=' . $year;
    $string = file_get_contents($url);

    # Read the JSON output into an associative array
    $result  = json_decode($string, true);

    print "<p>In $year, the prizes were awarded as follows:</p><ul>\n";
     ...  # see next slide
    print "</ul>";
  else {
    print "<p>Year value out of range; years range from 1901 to 2017</p>";

8.21. PHP code for Nobel Prizes (2)

returned JSON data is as follows (for year 1991):

     "surname":"de Gennes",
     "firstname":"Richard R.",
     "firstname":"Aung San Suu Kyi",
     "firstname":"Ronald H.",

8.22. PHP code for Nobel Prizes (3)

8.23. Links to more information

HTTP is covered briefly in Section 4.6 of [Comer]. Section 7.3 of [Tanenbaum] covers HTML forms and HTTP, and mentions CGI and PHP. Servlets are covered in Chapter 9 and JSP in Chapter 10 of [Moller and Schwartzbach]. Server-side processing of XML using PHP (and VB.NET) is covered in Chapters 11 (12) and 13 in [Jacobs].