DM 171: Week Six - eXtended Server Side Includes
XSSI: Simple Yet Effective Programming for the Masses
Click on a tab to reveal its content…
- In General
- Environment
- XSSI Commands
XSSI are powerful enough to replace functionally simple CGI scripts and do not require knowledge of Perl programming. One of the best sites to learn about simple programming with XSSI is “The World’s XSSI Cookbook” at http://www.std.com/web/help/xssi-cookbook.shtml. There will be many references to the “Cookbook” as well as some paraphrasing; it is a clearly written tutorial that I am so thankful for that I keep a copy locally on my hard drive for reference.
The Neighborhood
The server and your browser create some data known as environmental variables. Knowing these will give you some ideas to be used with if instructions embedded in your pages. The <!--#printenv --> command can be used to show which variables can come into play. Create a page with the code below or download this page to be placed in your exercise three folder to give you a list of the variables.
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>SSI Environmental Variables</title>
</head><body>
<h1>Server Side Includes - Environmental Variables
</h1><pre>
<!--#printenv -->
</pre></body>
</html>
What does it all mean? Check the next tab.
Environmental Variables
These are some of the variables that the server keeps track of, notice that not all of them are supported since the “Result” is sometimes (none). Each installation of the Apache Server Software can have its own unique setup.
The results shown are for the art.wallyzone.com server.
| Code | Description | Result |
|---|---|---|
| AUTH_TYPE | client authorization method if any | (none) |
| CONTENT_LENGTH | size of input posted from client | (none) |
| CONTENT_TYPE | MIME type of content | (none) |
| DATE_GMT | The current GMT time | February 7, 2012 |
| DATE_LOCAL | current time/date | February 7, 2012 |
| DOCUMENT_NAME | document name that was requested | xssi.shtml |
| DOCUMENT_URI | URL of the document | /dm171spring2010/schedule/week06/xssi.shtml |
| LAST_MODIFIED | document modified date | October 26, 2011 |
| PAGE_COUNT | number of accesses to current document | (none) |
| HTTP_REFERER | URL of the document the client came from | (none) |
| REMOTE_ADDR | Numeric IP address of the client | 38.107.179.237 |
| REMOTE_HOST | domain name of the client | (none) |
| REMOTE_USER | ID of user | (none) |
| REQUEST_METHOD | HTTP method: GET OR POST | GET |
| SERVER_NAME | server hostname | art.wallyzone.com |
| SERVER_PORT | the port used by httpd | 80 |
| SERVER_PROTOCOL | Which version of Httpd compliance | HTTP/1.1 |
| SERVER_SOFTWARE | The name of the server software | Apache |
| TOTAL_HITS | total pages served by server | (none) |
Time Format Codes
Use these codes as values for <!--#config timefmt="..." --> to get the desired results when you echo the DATE_LOCAL. Once again, the values shown are for art.wallyzone.com.
| Code | Description | Results |
|---|---|---|
| %a | abbreviated weekday name | Tue |
| %A | full weekday name | Tuesday |
| %b | abbreviated month name | Feb |
| %B | full month name | February |
| %c | locale's appropriate date and time | Tue Feb 7 13:36:52 2012 |
| %C | default date and time format | 20 |
| %d | day of month - 01 to 31 | 07 |
| %D | date as %m/%d/%y | 02/07/12 |
| %e | day of month - 1 to 31 | 7 |
| %h | abbreviated month name (alias for %b) | Feb |
| %H | hour - 00 to 23 | 13 |
| %I | hour - 01 to 12 | 01 |
| %j | day of year - 001 to 366 | 038 |
| %m | month of year - 01 to 12 | 02 |
| %M | minute - 00 to 59 | 36 |
| %n | insert a newline character | |
| %p | string containing AM or PM | PM |
| %r | time as %I:%M:%S %p | 01:36:52 PM |
| %R | time as %H:%M | 13:36 |
| %S | second - 00 to 61 | 52 |
| %t | insert a tab character | |
| %T | time as %H:%M:%S | 13:36:52 |
| %U | week number of year - 00 to 53 | 06 |
| %w | day of week - Sunday=0 | 2 |
| %W | week number of year - 00 to 53 | 06 |
| %x | Country-specific date format | 02/07/12 |
| %X | Country-specific time format | 13:36:52 |
| %y | 2 digit year - YY | 12 |
| %Y | 4 digit year - YYYY | 2012 |
| %Z | timezone name | EST |
We learned last week about including other files with the include command:
<!--#include virtual="path_to_file" -->
The other commands are well documented at “The Worlds XSSI Cookbook” much better than I could; pay special attention to:
#config timefmt- to configure the homework footer date#echo var- to get the date (and other variables)#if expr,#elif expr,#else,#endif- the four commands used to craft your if/else programming for the contextual menu homework requirement#set varwithvalue- allow you to set your own variables if needed- The comparison operators and Boolean operations section is important to look over to use in your if/else programming.