SSI assignment explained

This week we learn about server side commands.

Preparation:

Text: none

CD: (optional) View lesson 7

I will post the video lecture after I make it on Tuesday

Server side commands are commands that are directed toward the web server. A server side command might ask the server to display today's date and time, or it might direct the server to write two paragraphs of text to your web page that are saved in a separate file. To be clear, the server carries out these commands, not the browser.

When a visitor wants to load your page into their browser, they type in the URL, and that sends a request out to the server where your page is stored. The server receives the request and sends the page to the person who requested your page.

Most servers can do more than grab a web page and send it back; they can parse the document. When the server parses a document, it searches through the page looking for special commands that it recognizes. When it finds a command like "write today's date" or "insert this code snippet", it acts on the command and rewrites your web page according to the commands, before sending it on to your browser.

However, parsing can take a lot of computing power. Servers do not typically parse web pages; they usually ignore page content and just deliver the file. If you want your document to be parsed, you need to alert the server by naming the file with an extension of .shtml. When the server processes any document that ends with .shtml, it knows that it has to check for server side commands before sending it on its way. Note: not all servers are configured to carry out server side commands, but our student server will do it for us.

The "echo" Command

Have you ever visited a web page that displayed today's date and time, or the date a file was last modified? This is done with the "echo" server side command. The server is constantly keeping track of many different variables and is able to write them to your pages if you like.

The echo command, which writes a variable to a page, looks like this: <!--#echo var="DATE_LOCAL"-->

The '#' at the beginning of the comment tells the server that this is a command. This is followed by a keyword, in this case "echo", which is a command that tells the server to insert the value of an environmental variable into the web page. In this example the variable is "DATE_LOCAL". This code causes the server to write the server's date and time onto the page wherever you placed the command.

Please note that the value of the var attribute is case and space sensitive. The code listed above is correct. The examples shown below will not work.

<!--#echo var="date_local"-->
<!--#echo var="Date_Local"-->
<!--#echo var=" DATE_LOCAL "--> (spaces around the quoted value)

Examples of environmental variables that are used regularly include:

  • DATE_GMT
  • DATE_LOCAL
  • DOCUMENT_NAME
  • DOCUMENT_URI (careful, this is URI, not URL)
  • LAST_MODIFIED
  • SERVER_NAME
  • SERVER_SOFTWARE

The "include" Command

The server side command that is probably the most useful and powerful is the "include" command, also known as a "Server Side Include" or "SSI". To illustrate how SSI works, you should compare it to a word processor. You can insert a header and footer into a 100-page manuscript and be assured that the header and footer will appear on every page. If you modify either the header or the footer, your changes will appear on each of the 100 pages. Using SSI is even more powerful, in that it allows you to command your server to include standard content on any part of your web page, not just the header and footer.

If you want to use SSI, take a look at the content of your site and identify the elements that are repeated on every page. If you use the same group of links or contact information at the bottom of 100 web pages, it would be much more efficient to create a single file called "bottom.txt" and have the server include it in all pages. The down side is that you would have to remove the links and contact information from all 100 HTML documents and substitute a single line of code that refers to the "bottom.txt" file.

<!--#include virtual="bottom.txt"-->

That may seem like like a lot of work because you are switching to SSI after already having created the site, but if you use SSI right from the start while creating your site this technique can save you hours of time.

Notice that the external file is not an HTML file. You do NOT name your file "bottom.html"; instead you name it "bottom.txt" or even simply "bottom". (You can fool a text editor into doing this by putting quotes around the name when you first save it.)

For Credit:

Don't forget - you can only test your files if they are loaded on the server first!
    1. (10 pts) Create a page named environmental.shtml that displays at least 4 environmental variables.

    2. (20 pts) On that same page use SSI to include the contents of an external file named ssi.txt. This file might contain, for example, a nav bar or contact information.

    3. (10 pts) Add some style to your page! Yes, you can use CSS commands along with SSI commands. The server will write the SSI and the browser will take care of interpreting your CSS. Name your CSS file ssi.css.

    Upload your 3 files (environmental.shtml, ssi.txt, and ssi.css) to the server. Upload them directly into your public_html folder, not into a subfolder.

    Each of your webpages must include a W3C validation icon for XHTML 1.0 Strict at the bottom. You should use the W3C validator to check your XHTML code and your CSS code. Links to these validators are on the resources page. Note that points will be deducted from your score for each error in your XHTML or CSS code.

  1. Class Evaluation - no points but your comments are extremely helpful.
    Please answer the following questions by email.
    1. What did you enjoy most about the class?
    2. What did you enjoy least about the class?
    3. Was the class too hard? Too easy? Just right? How should I make it easier/harder?
    4. The course textbook was (choose one of the following and explain): indispensable, a great help but I could have survived without it, somewhat helpful, not helpful at all.
    5. Did you find the course website helpful? Can you offer suggestions for improvement?
    6. The garden site of the course website was (choose one of the following and explain): indispensable, a great help but I could have survived without it, somewhat helpful, not helpful at all, I never even looked at it.
    7. The resources page of the course website was (choose one of the following and explain): indispensable, a great help but I could have survived without it, somewhat helpful, not helpful at all, I never even looked at it.
    8. Were the assignments appropriate for helping you to learn the class content?
    9. Did the quizzes appropriately determine your level of understanding of the class content?
    10. Were your questions answered in a timely and helpful manner?
    11. Any additional comments?
    12. Please give the class an overall rating from 1 - 10 with 10 being the highest.

Valid XHTML 1.0 Strict

Website designed by Bartosz Brzezinski
Content developed by Linda Hemenway - lhemenway@santarosa.edu