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. Common gateway interface (CGI)
  12. HTML forms and CGI
  13. Perl code for www-inventor.pl
  14. Server-side processing technologies
  15. PHP
  16. PHP code for www-inventor.php
  17. Processing XML with PHP (1)
  18. Processing XML with PHP (2)
  19. Modifying server-based information
  20. addAcronymAction.php
  21. addAcronymAction.php explanation
  22. 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.pl"
  <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. Common gateway interface (CGI)

8.12. HTML forms and CGI

8.13. Perl code for www-inventor.pl

print "Content-type: text/html", "\n\n";
$query_string = $ENV{'QUERY_STRING'};
($question, $answer) = split (/=/, $query_string);
print "<html>", "\n";
print "<head><title>WWW Inventor</title></head>", "\n";
print "<body>", "\n";
if ($answer eq "Berners-Lee") {
   print "Congratulations, you answered correctly.";
} else {
   print "Sorry, the correct answer is Berners-Lee.";
print "</body></html>", "\n";
exit (0);

8.14. Server-side processing technologies

8.15. PHP

8.16. 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.17. Processing XML with PHP (1)

8.18. Processing XML with PHP (2)

8.19. Modifying server-based information

8.20. addAcronymAction.php

  $acronym = $_GET['acronym'];

  $xmlDoc = new DomDocument();

  $newAcronymElement = $xmlDoc->createElement("acronym");

  $root = $xmlDoc->documentElement;

  if ($xmlDoc->save("/home/ptw/public_www/teaching/IWT/server/acronyms.xml"))
    print "<p>You have successfully updated the XML document</p>";
    print "<p>An error occurred</p>";

8.21. addAcronymAction.php explanation

8.22. 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].