\n"; } else { header("Content-type: $mime_type; charset=utf-8"); } ?> > CSCI 903 Assignment 2

CSCI 903 Assignment 2

Overview

For this assignment, you are to complete the first assignment so the XHTML validation link actually works.

In addition, you are to “deploy” your web site by copying both files to your H:\htdocs directory in the lab. As discussed in class, you can access this directory while logged into any computer in the lab, and the effect will be to access the htdocs directory under your “home” directory on the Oak server.

Instructions

First, replace the <?xml…, <!DOCTYPE…, and <html… lines at the beginning of the web page with the following code:

<?php $html_attributes="lang='en'"; if ( array_key_exists("HTTP_ACCEPT", $_SERVER) && (stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml") || stristr($_SERVER["HTTP_ACCEPT"], "application/xml") ) || (array_key_exists("HTTP_USER_AGENT", $_SERVER) && stristr($_SERVER["HTTP_USER_AGENT"], "W3C_Validator")) ) { $html_attributes = "xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'"; header("Content-type: application/xhtml+xml"); echo "<?xml version='1.0' encoding='UTF-8'?>\n"; } else { header("Content-type: text/html; charset=utf-8"); } ?> <!DOCTYPE html> <html <?php echo $html_attributes;?>>

Note: Be sure to paste this code at the very beginning of the web page. In particular, a blank line, or even a single space character, before the <?php line will “break” the web page (Why?), a very difficult bug to locate. (Why?).

Second, the file name for the web page has to be either index.php or index.xhtml. There are two reasons for this: (1) our Apache web servers are configured so that only files with a .php or .xhtml extension will be processed by the PHP module. If you don’t use one of those extensions (for example, if the extension is .html), Apache will pass the PHP code embedded in the file back to the browser, which will not know what to do with it, probably resulting in the user seeing an error message rather than your web page. (2) our Apache web servers are configured so that a request for a directory rather than a file will be treated as a request for a file named index.xhtml, index.php, or index.html located in that directory instead. This convention is one of the techniques we can use to simplify the URLs that users need to deal with.

The choice of whether to use the .php or .xhtml extension is up to you: as discussed in class, Dreamweaver will syntax-color either the HTML or the PHP code depending on which extension you use, but they are otherwise equivalent.

Create a subdirectory named css under your H:\htdocs directory, and put your stylesheet there. You will have to adjust the link to it in your index page to reflect this change.

These instructions assume you are already comfortable with accessing your account in the TREE lab. If not, TREE Lab Information can help. But note that some of the information there is out of date. Aside from the course numbers (this is CSCI 903, not 090.3), that information does not take into account the Apache web server that now runs on Oak, suggesting that you have to keep your work only in your Profile. Starting this semester, you will submit assignments by putting your code into your H:\htdocs directory.

Note that there is no requirement for you to use Dreamweaver for this assignment. You may do so if you wish, but you can use any code editor you like to prepare the two files for this assignment.

Test and Submit

Test

You know from our discussion of “why XML” that the goal of this course is not only to introduce you to how to code, but how to code well. Starting with this assignment, there is a basic requirement for all assignments that you submit, whether mentioned explicitly in the assignment web page or not: test your code carefully before submitting it for grading. Make sure it does what it is supposed to do; make sure it handles “corner cases” correctly; and make sure it meets the specifications given in the assignment web page.

For this assignment, testing consists of putting your web page and style sheet in your H:\htdocs directory, and viewing it using the URL, http://oak.cs.qc.cuny.edu/~stpe9999. Of course, you have to substitute your own account for Perfect Student’s.

Make sure the page shows exactly what the assignment calls for: a level-1 heading, 15-20 paragraphs, and links to the XHTML and CSS validators at the bottom. Pay close attention to the beginning of the page to make sure there are no stray characters before the level-1 header, which would indicate a problem with the PHP code inserted at the beginning of the page.

Make sure the page behaves as it’s supposed to. Hover your mouse over everything, you are testing corner cases here, and be sure the text of each paragraph except the fourth one turns red when you hover over it, that the fourth one turns blue, and that hovering doesn't affect anything else on the page.

Make sure the two validation links work and that both give you no warnings or errors. The only exception is that the XHTML validator should give a warning that the “HTML5 Conformance Checker” (the validatory itself) is still experimental. Be sure the HTML validator recognizes the page as HTML5 and the CSS validator recognizes the page as CSS3.

Finally, make sure the web page is being delivered as XML. In class, we'll cover how to get the browser to show the request and reply headers so you can verify it; for now use your browser's "view source" option to look at the source code for your web page. The first line it shows has to be the <?xml… declaration. All major browsers have a view source option, but it’s in different menu places on different browsers. Look under the View menu for “Developer Tools” or “Page Source,” or ask Mr. G. for help. (If you don’t know who Mr. G. is, you can go to his website, where you will find answers to many questions.)

Correct anything that is wrong before submitting the assignment.

Submit

When you are ready to submit the assignment, send me an email:

That’s it. When I get your email, I’ll look at your web page on oak, and send you back your grade by email. The grade for this assignment will simply be “ok” or “not ok”. See the course syllabus to learn how to interpret these grades.

To get full credit, you have to send the email to me by midnight of the due date (February 12).

As soon as you receive the email from me with your grade, use the form on the course schedule to be sure I have recorded your grade correctly