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
Trying 193.61.29.21...
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">
<head>
<title>Computer Science and Information Systems Birkbeck University of London</title>

...

</body>
</html>

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"
      method="GET">
  <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" />
</form>

8.11. Common gateway interface (CGI)

8.12. HTML forms and CGI

8.13. Perl code for www-inventor.pl

#!/usr/bin/perl
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

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

8.17. Processing XML with PHP (1)

8.18. Processing XML with PHP (2)

8.19. Modifying server-based information

8.20. addAcronymAction.php

<html>
  <head/>
    <body>
<?php
  $acronym = $_GET['acronym'];

  $xmlDoc = new DomDocument();
  $xmlDoc->load("/home/ptw/public_www/teaching/IWT/server/acronyms.xml");

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

  $root = $xmlDoc->documentElement;
  $root->appendChild($newAcronymElement);

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

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