Simple Website Software (SWS)

SWS layout

SWS is my attempt to provide software to generate a reasonably modern looking web site while requiring a minimal amount of effort to set up, yet keeping the HTML pages independent so they can be easily editted and verified outside the web site.

SWS requires PHP version 4.1 or above and consists of only a small number of files. It uses cascading style sheets (CSS) to control the basic look and feel and has the basic layout (but not ugly appearance) of that shown to the left. If you want a web site which has different components than those you see here, SWS is not for you.

Components

There are only a few components to your basic SWS web page:

  1. Banner - an optional box across the top of the page. This is provided as a file containing a fragment of HTML.

  2. Left hand menus - a required set of links organized in one or more blocks. Each block has a title and consists of zero or more static links. This is provided as a file containing partial HTML address tags.

  3. Middle - is where the basic HTML you provide is shown. This is provided as a file which is often named similar to your PHP program.

  4. Right hand menus - an optional set of links, similar to those on the left hand side.

  5. Footer - generated HTML which shows a copyright and date for each page of HTML.

So what's a real SWS web site look like? You're looking at one example right here at SWS at SourceForge. Here are some other web sites to get ideas of what can be done using SWS:

The SWS source is available at SourceForge.

Interesting Features

SWS pages are rendered quite fast by your PHP web server. There is no operating system dependency here - you may use a Unix (Linux) or Windows-based server. The only software requirement is that you have PHP available. You code each page in PHP, but the PHP is very simple and almost always looks the same. You don't need to be much of a PHP coder.

SWS requires no database to render it's pages.

Any authentication uses the normal web server mechanism (e.g. .htaccess files for Unix Apache).

Menus can be selectively displayed based on what section of the web site is being displayed. If one selects 'vacations', then you can show a menu of vacation links. Move elsewhere and the menu disappears.

Menus can be selectively displayed based on whether the user is authenticated ('logged in') or not. Different menu blocks can be shown to different people.

A few lines of comments at the top of your HTML can be used to inject HTML of interest like a centered header (h2), a link to code to print the HTML without the navigation (printpage), a visual hint how you navigated to this page (breadcrumbs), or something else specific for this page only (call). Read on for details.

A utility program called showfilelist.php is provided to generate simple lists of links. This program reads a simple ASCII file and generates the HTML for you keep your interface very simple.

An entire SWS installation and setup consists of only a small number of files, all centralized in one directory. Your basic HTML remains in HTML files so you can develope it and test it as you normally would. You only use a small PHP program to tie it all together so the pages have a consistent look and feel. This keeps things easy for you to create and maintain your web site.

Files

An SWS web site is driven by small PHP programs which renders the HTML you provide and adds the banners and menus for the web site. Here's a typical PHP program. If this is named 'index.php', then it will display 'index.html' from the same directory. Note you must set $SWSDIR to specify where the SWS files are to be found. Your SWS pages typically consist of a file like this and the HTML you normally would show.

<?php $SWSURL = '/sws'; $SWSDIR = $_SERVER['DOCUMENT_ROOT'] . $SWSURL; // Where all my files are include_once "$SWSDIR/common.php"; session(); // Watch for authorization to expire do_page(); ?>

While the example above is almost always sufficient for your needs, your PHP can set the title or read any arbitrary file as you see in these examples:

<?php $SWSURL = '/sws'; $SWSDIR = $_SERVER['DOCUMENT_ROOT'] . $SWSURL; // Where all my files are include_once "$SWSDIR/common.php"; session(); // Display .html file with the same name as this file $title = 'This is My SWS Web Site'; do_page($title); ?> or this example <?php $SWSURL = '/sws'; $SWSDIR = $_SERVER['DOCUMENT_ROOT'] . $SWSURL; // Where all my files are include_once "$SWSDIR/common.php"; session(); $title = 'This is My SWS Web Site'; $file = 'myswsfile.htm'; $html = findfile($file); do_page($title, $html); ?>

HTML File Format

The HTML files your PHP programs will display need to have valid HTML directives in them. Many times a browser will ignore errors. Since your HTML is wrapped in a <table> directive by SWS routines, it is possible your pages can cause the browser to show you quite a mess. You will find it useful to remove the header and trailer lines of your HTML pages for the best results. Specifically you should remove these HTML directives:

  • Just the tags <html> and </html>
  • Everything from and including <head> through </head>
  • Everything from and including <title> through </title>
  • Everything from and including <style> through </style>
  • Remove the tags <body> and </body>
  • All <meta> tags

There are times when your HTML document header contains information you really want to control. SWS generates the headers and by the time your HTML file is read, the headers have already been sent. You can include some of details specific to your HTML file as comments where SWS will pick the information out and put it in the headers.

Each of these appears as a single line of comment to HTML (e.g. <-- key=value -->.). The comment start (<--) must start in column one and must end on the same line (no wrapping or multi-line mode is supported). The following key=values are recognized:

  • FOOTER=htmlstring can be used to force the page footer (after the last </table>) to the string of HTML provided. Remember this must all appear on one line, but may contain any valid HTML. Do not include any </html> or </body> tags.

  • INSERT=path_to_file can be placed anywhere in your HTML. When encountered it will read the file 'path_to_file' of HTML and add it to the page being rendered. If the file cannot be found, your HTML will include an HTML comment that tells you the file was not found. No error message will appear on your HTML page. For instance on one site I run a cron job to daily to generate a simple list of files that have changed and creates whatsnew.html as a small fragment of HTML.. This file is then 'inserted' in the page of HTML being rendered.

  • KEYWORDS=meta_tag_words can be used to set META tags in your HTML. You may define more than one such line. If you don't know what this is about, you don't need it. SWS will extract the keywords and put them in the header of the document that is rendered. If you are viewing this document at the SWS Home Site, look at the source HTML rendered by your browser (probably control-U will show you this) and notice the META tags at the top.

  • OPTIONS=keywords can be used to generate extra HTML at the top of the HTML in your file. The following are recognized:

    • breadcrumbs which generates a line of HTML hinting how you got to the page being viewed (e.g. Home -> Venture -> Readings). This line is extracted from the directory names in the URL.

    • call(name) which references $CALLNAMES in sws/local_config.php (see description below) and allows you to insert a link at the top of the HTML to call code you have written.

    • h2 which generates an <h2> directive at the top of the page showing the TITLE (see below) you specified.

    • printpage which generates a line of HTML on the page Print This Page. When this link is selected your browser will re-render the page without the navigation, headers and footers (e.g. just the HTML file).

  • STYLE=htmlstring can be used to insert a <style> directive to be put in the HTML header. Whatever is provided is wrapped in <style>, so you probably want to code this like the example shown below.

  • TITLE=string can be used to set 'string' to the title of the HTML document, i.e. in lieu of <title>/</title>.

For example, here's a fragment of an HTML file to be rendered by SWS:

<!-- KEYWORDS=battles colorado river --> <!-- KEYWORDS=white water rafting trip summer 1995 --> <!-- STYLE=@import url("mycss.css"); --> <!-- TITLE=Terry Gliedt Battles the Colorado River --> <!-- OPTIONS= printpage h2 breadcrumbs call(Say_Hi --> <!-- FOOTER=<div class="footer"><blink>Problems?<a href="mailto:you@there">you@there</a></blink></div> --> <p align="center">What'd You Do On Vacation, Terry ?</p> etc.

Authentication

A convenient feature of SWS is to display differing menu blocks based on who is viewing your pages. Of course, in order for you to decide this, the user must first 'login' by visiting a protected web page where you get a prompt for a user and password. For instance, suppose a user visited the page 'secret/login.php'. If you have provided a .htaccess file to control who can access this page, the user will be prompted for a userid and password. After the prompt the following PHP code might be invoked (see secret/login.php):

<?php $SWSURL = '/sws'; $SWSDIR = $_SERVER['DOCUMENT_ROOT'] . $SWSURL; // Where all my files are include_once "$SWSDIR/common.php"; // Actually creates session, sets expiration time session(1); // Go to start of web site $proto = 'https'; // Change if you need to $newurl = $proto . '://' . $_SERVER['HTTP_HOST'] . '/'; header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); header('Cache-Control: no-store, no-cache, max-age=0, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache'); header("Location: $newurl"); ?>

In this case a PHP variable ($_SESSION['REMOTE_USER']) is set to the userid from the password prompt. This is remembered and available for other SWS PHP pages to use. A timeout value is also set, so you can configure your web site to require re-authentication after a certain number of seconds.

Similarly, code like the following can be used to 'logout' and lose the SWS authentication (see secret/logout.php):

<?php $SWSURL = '/sws'; $SWSDIR = $_SERVER['DOCUMENT_ROOT'] . $SWSURL; // Where all my files are include_once "$SWSDIR/common.php"; // Force expiration of authenticated period session(); $_SESSION[SESSTIME] = 0; $_SESSION[REMOTE_USER] = ''; // Go to start of web site $proto = 'http'; // Change if you need to $newurl = $proto . '://' . $_SERVER['HTTP_HOST'] . '/'; header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); header('Cache-Control: no-store, no-cache, max-age=0, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache'); header("Location: $newurl"); ?>

Optional Menus

Another convenient feature of SWS is to display differing menu blocks based on what the current "topic" is. This requires that your PHP code sets a global variable $SHOWBLOCK with some name (e.g. 'vacations'). In your menus you specify blocks which only are shown when the topic is 'vacations'. An example will help:

BLOCK=Professional Life <a class="menus" href="/resume/index.php">Resume</a> BLOCK=Vacations SHOWONLY=vacations <a class="menus" href="/vac/summer95.html">A Water Experience</a> BLOCK=Secret Vacations SHOWONLY=secretvac [tpg] <a class="menus" href="/vac/summer96.html">Another Water Experience</a> BLOCK=Odds and Ends <a class="menus" href="/personal/">Personal Details</a>

The second menu block shown above will appear as long as your PHP code does the following:

<?php $SWSURL = '/sws'; $SWSDIR = $_SERVER['DOCUMENT_ROOT'] . $SWSURL; // Where all my files are include_once "$SWSDIR/common.php"; session(); $SHOWBLOCK = 'vacations'; // Force vacation menus to be seen do_page(); ?>

Installation and Setup

The download file is a simple tar file. Extract the distribution with tar xzf sws-*.tar.gz on a Mac/Unix machine or use your Windows unzip program (e.g. 7-Zip). This creates a directory sws with the distribution. The next step is to copy the SWS files for use on your web server. You'll need to know the path to your webserver DOCUMENT_ROOT and have write access to it.

  • Windows Users have no automated install, so you will do the install manually. (I'd be happy to distribute yours, if you send it to me.) What follows is pseudo-code, not a proper batch script. This assumes you want SWS as /sws in the web server DOCUMENT_ROOT.

    cd sws DEST=path to your DOCUMENT_ROOT mkdir $DEST/sws copy web/sws/styleSWS.css $DEST/sws/styleSWS.css copy model_lhmenu.txt $DEST/sws/SWS.lhmenu.txt copy model_banner.html $DEST/sws/banner.html copy install/index.html $DEST/sws/index.html copy model_index.php $DEST/sws/index.php copy model_config.php $DEST/sws/local_config.php # If you want login to work (change directory name as you want) mkdir $DEST/sws/secret copy web/secret/* $DEST/sws/secret # If your SWS is not installed at URI /sws, then you must change /sws to /yourpath # in all the PHP files in this new directory


  • Unix/Mac Users can complete the install by invoking the script install/initial_setup.sh.

    tar xzf sws-*.tar.gz cd sws install/initial_setup.sh We are about to create a sample set of installation files for a web site that wants to use SWS. Enter path to the SWS tgz file to install (e.g. sws-2.0.tar.gz): sws-2.0.tar.gz OK - I'll install 'blah/blah/sws-2.0.tar.gz' Enter the full path to the directory where SWS is to be installed. We will create a directory 'sws' here as well as index.php Enter path or just press ENTER to stop: /var/web/html OK - I'll install in '/var/web/html' Enter the URI in your web site where SWS will be installed. This is almost always /sws Enter the URI ir or just press ENTER for the default: /sws [filelist deleted] OK, '/var/web/html' exists and above this is a list of the files there. Install 'blah/blah/sws-2.0.tar.gz' for URI '/sws' ? [y/n] y Installing blah/blah/sws-2.0.tar.gz Installed directory 'sws' Correct URI in sws/model_index.php [details deleted] Installed the install instructions as your index.html file. You'll want to change this. The directory 'secret' already exists, so Login/Logout probably will not behave Installed index.php Installed local_config.php. You will need to edit this. See instructions at sws/index.html Visit the URL http://yourwebserver/sws

Edit the file local_config.php with your favorite ASCII editor (not Word). The example provided is well commented, but you should remember this is PHP code you are providing. You must get the PHP code syntax correct. The following variables will be of most interest:

 
$SITENAME
name of your site - appears in default footer.
$LHMENUS
full path to a file which defines the left hand menus.
$RHMENUS
full path to a file which defines the right hand menus. This is optional.
$LOCALLHMENUS
an array of menu files which might exist in the current directory where the HTML file is found. These have the same format as any other menu block, but will only be read and processed when showing files from this directory. This is optional.
$LOCALRHMENUS
an array of menu files which might exist in the current directory where the HTML file is found. These have the same format as any other menu block, but will only be read and processed when showing files from this directory. This is optional.
$RHMENUS_IF_AUTH
controls whether SWS dislays the right hand menus if the user is authenticated.
$SITEBODYCLASS
Specify the class tag on the <body> directive here. This is optional.
$SITEJS
full path to where the CSS for this site is to be found.
$SITELOCALJS
is an array of additional paths to more CSS files to be included in the headers. This is what $SITEJS should have been when SWS was written. Don't be confused by the JS in the variable name. This is for CSS files only (sorry).
$JSCRIPT
is a string to be included in the page header. This allows you to insert <script language=JavaScript src=...> directives (or anything else for that matter). This is another example where SWS did a poor job in providing a generalized solution to insert Javascript or CSS includes in the page header.
$BANNERFILE
full path to a file which provides the HTML for the banner. This is optional.
$HEADERLINES
defines a set of lines added to the <head> block of every page generated by SWS. This is a good place to put <meta> tags as well as Javascript (<script>) definitions.

Your menus are controlled by files you specify in the local_config.php file. Edit the menu file (default is SWS.lhmenu.txt) with your favorite ASCII editor (not Word). The syntax of the file is shown below.

Defining Menu Blocks

Menus are defined in a simple ASCII file. One must first define a block and follow that with lines of HTML address directives for the links. Several files are supported, one for menus on the left side and optionally one on the right (see $LHMENUS, $RHMENUS in local_config.php). These menus are 'global', that is, the $LHMENUS and $RHMENUS files are processed each time the SWS page is rendered.

You may also specify menus on a per directory basis by creating one or more files in the directory being referenced (see $LOCALLHMENUS and $LOCALRHMENUS in local_config.php). In this case the $LOCALLHMENUS and $LOCALRHMENUS files are not processed unless the directory referenced in the URL contains these files. For instance if $LOCALLHMENUS was set to two files ('AB.txt' and 'CD.txt') and your URL ended with '.../abc/showpeople.php' then SWS would look for the files .../abc/AB.txt and .../abc/CD.txt. If these were found, then the menus defined in AB.txt and CD.txt would be included in the page that is rendered. I find it very useful to keep the menus for some URL in the directory where the data for the URL lives.

Regardless where the meun files was found, they files all look the same and follow these rules:

  • A # in column one is a comment and is ignored

  • Blank lines are ignored

  • BLOCK=name [SHOWONLY=name] [authlist] defines a block with a particular name. If SHOWONLY is provided, it identifies the name of a block that is to be displayed if the PHP variable $SHOWBLOCK matches 'name'. If this is not matched, the menu block is not displayed. SHOWONLY is optional. You may also specify a blank delimited list of authorized users in square brackets. If the user has logged in and his/her name is in the list, then this menu is shown, else it is not shown. If the name of the block is NOSHOW, the block name is not shown.

  • BLANKLINE in column one will insert a spacer line in a menu

  • Lines defining a block are lines of HTML beginning in column 1. They either define a single menu line or a block of HTML:
    1. Complete HTML address directives, all on one line like:
         <a class=menus href="/somewhere">Words in Menu</a>
            or
         INDENT<a class=menus href="/somewhere">Words in Menu</a>
      See the variables $MENUITEMHTML and $MENUINDENTHTML in the local_config.php file for details on how these are formatted.

    2. Several lines of HTML. The HTML opening directive starts on the first line beginning in column one. The same ending directive is found a subsequent line, again beginning in column one.

Here's an example that defines a number of blocks and shows all the combinations:

# Just shows 'Home' and a small graphic. No block name # This block begins and ends with a <p> directive in column one. BLOCK=NOSHOW <p class="tpgmenu"> <a href="/index.php" class="tpgmenu"> <img src="/graphics/tpg3yr.gif" hspace="5" vspace="5" border="0" width="33" height="51" align="right"/> Home<br>tpg </a> </p> # This is only shown when $SHOWBLOCK is set to 'vacations' # which should be done by the PHP scripts for the topic 'vacations' BLOCK=Vacations SHOWONLY=vacations <a class="menus" href="/vac/summer95.html">A Water Experience</a> <a class="menus" href="/vac/gc/" target=_blank>Grand Canyon</a> # This is only shown when $SHOWBLOCK is set to 'ourvac' # and will only be shown when 'you' and 'me' are logged in. BLOCK=Vacations SHOWONLY=ourvac [me you] <a class="menus" href="/vac/summer96.html">Another Experience</a> # These are simple one-line links. Notice the use of the class= # keyword. 'menus' is defined in the SWS .css file. # You'll want to use class to control the look of the links. BLOCK=Professional Life <a class="menus" href="/resume/index.php">Resume</a> <a class="menus" href="http://phpsws.sourceforge.net/" target="_blank">SWS Web Site</a> <a class="menus" href="/toolbox/linux.php">Linux</a> BLOCK=Personal Projects INDENT<a class="menus" href="/win/" target=_blank>Coping with Windows</a> INDENT<a class="menus" href="/ukdict/index.php">UK English for the American Novice</a> # If the user is logged in and is 'mike' or 'tonee', then show this menu BLOCK=Private [mike tonee] <a class="menus" href="/secret/index.php">Password Box</a> <a class="menus" href="/secret/directions.html">Directions to Hideaway</a>
SWS layout

Configuring CSS/Javascript

SWS makes extensive use of Cascading Style Sheets (CSS). This allows one to centralize all the attributes of the HTML tags to control the look of each. Want to use a different color scheme? Just change a few background colors in one file and it's done.

A reasonable default CSS file is to be found in sws/styleSWS.css. Feel free to change this name, just be sure to set the name in $SITEJS in local_config.php.

Edit the CSS file and compare the colors in the screen image showing all the CSS fields above. Start changing things as you want. You'll notice there are a series of CSS classes which control various parts of each component of a page.

SWS allows you to specify several ways to define HTML include statements in your page to load additional CSS and Javascript files. Unfortunately, this evolved over time, so there are several PHP variables that could be involved. Read more about the variables $SITEBODYCLASS, $SITEJS, $SITELOCALJS, $JSCRIPT in the section preceding this.

Possibly Useful Functions in common.php

do_page(title,centerhtml)

This SWS code allows you to specify the title or the page to be generated and/or the HTML to be shown. Both fields are optional. If no title is specified, then the title will be set by the TITLE= keyword (if provided). If no HTML is provided, the HTML will be read from a file whose filename is the same as this PHP code. That is, if the PHP file is called 'index.php' and no centerhtml is provided, then the routine will look for 'index.html' or 'index.htm' and use the contents of that file.

findfile()

This SWS code provides a simple way for you to create one PHP program which can read a variety of HTML files, avoiding the problem of creating separate PHP files for each HTML file. Your PHP program should be called with a parameter file=name which identifies a .html file in the same directory as your PHP program. For instance, if you create vacations/showme.php then calling it by

    showme.php?file=china

will cause showme.php to search for 'china.html' in the 'vacations' directory. For security reasons, you may not provide relative paths to other HTML files outside of vacations. The complete 'showme.php' program would look like the following. The function findfile is provided by SWS in common.php.

<?php $SWSURL = '/sws'; $SWSDIR = $_SERVER['DOCUMENT_ROOT'] . $SWSURL; // Where all my files are include_once "$SWSDIR/common.php"; session(); // Watch for authorization to expire extract(isolate_parms( 'file')); // Get parms passed to me $html = findfile($file); // Get $file.HTML, maybe do_page('',$html); ?>

session(setup)

This SWS code provides a simple way for you to setup HTML cookies so SWS can keep track of how long a login session lasts. Setup should be '1' only on pages which use HTML authentication. This allows SWS to control what menus are generated for certain authenticated users.

External PHP script - showfilelist.php

The PHP program showfilelist.php generates simple lists of links. Yes, you can do this in HTML, but for some it's far easier to edit a simple ASCII file and avoid the chance of generating invalid HTML. Use this program if you find it useful or ignore it as suits you. You can invoke showfilelist.php with a simple URL likes this:

<a href="/sws/showfilelist.php?dir=mydocs&file=docs.txt">See docs</a>

The file to read is specified by the file= keyword on the invocation. A subdirectory relative to htdocs may be specified with a keyword dir=. The file must contain lines of keyword=value lines (one line only). The keyword pagetitle will set the HTML <title> directive. The keyword header will generate an HTML <h2> directive at the top of the page. Header is not optional.

The rest of the file consists of keywords describing lists, organized as sections. The keyword section will generate an HTML <h4> directive to start a section of the document. The keywords item and url provide information for an HTML list item and an address reference for a link. An example will make this all much more clear:

pagetitle=Software Documentation header=Select From These Documents section=<font color="red">Statistical Software</font> item=Allegro url=allegro/ item=ASPEX, nonparametric linkage analysis of sib pair data url=aspex/ section=<font color="red">Our Environment</font> item='Dot' file examples url=dotfiles/README.txt item=Machine List url=machines.txt item=Printers url=printers

which generates the following HTML (remember, the links exist only as examples):

Select From These Documents

Statistical Documentation

Our Environment

Advanced Topics

Changing Look Based on Who is Logged In

Sometimes you want to change the values of in the local_config.php file based on what user is logged in. This requires a little trickery since the variables in local_config.php are defined before the user name is defined. To get around this an override function is supported. In the local_config.php file, code a subroutine like the following and put the logic there you want:

/*--------------------------------------------------------------- # CONFIG_OVERRIDE - This code is called when the user is logged # in and allows one to change defaults from those # defined above. # # Parameters: # user - user we logged in as # # Returns: # nothing #---------------------------------------------------------------*/ function CONFIG_OVERRIDE($user) { global $SITEJS, $BLOCKNAMEHTML, $MENUITEMHTML; if ($user == 'janedoe') { $SITEJS = "/sws/style$user.css"; $BLOCKNAMEHTML = ''; $MENUITEMHTML = "<img src='/sws/redtri.png' alt='arrow'&/> "; } }

Show Data From a Different Name?

Sometimes the HTML you wish to show is not named the same as your PHP code. To deal with this case, just provide the HTML to do_page() directly. Note the call to findfile sets the variable $REVISIONDATE which is used in the footer. If it's not set, it is not used. In these cases your PHP code will look like this:

<?php $SWSURL = '/sws'; $SWSDIR = $_SERVER['DOCUMENT_ROOT'] . $SWSURL; // Where all my files are include_once "$SWSDIR/common.php"; session(); // Watch for authorization to expire $title = 'This is My SWS Web Site'; // Could also be set in HTML file $file = 'sample'; $html = findfile($file); // Get sample.html do_page($title, $html); ?>

Show Data From a Non-Standard File?

Sometimes the HTML you wish to show comes from a file that is not named .html or .htm. We handle these cases pretty much like that above:

<?php $SWSURL = '/sws'; $SWSDIR = $_SERVER['DOCUMENT_ROOT'] . $SWSURL; // Where all my files are include_once "$SWSDIR/common.php"; session(); // Watch for authorization to expire $title = 'This is My SWS Web Site'; $file = 'sample.public'; $lines = file($file); // Provide the HTML for center $html = implode('',$lines); $REVISIONDATE = "<br>Last Revision: " . date('M d, Y', filemtime($file)); do_page($title, $html); ?>

Use Symlinks to Avoid All Those PHP Files

On Unix/Mac systems you can use symbolic links so that one PHP file is read for many files. Consider this directory:

training> ls -l -rw-r--r-- 1 123284 tpg 81625 Aug 18 11:32 2002handbook.html lrwxr-xr-x 1 123284 tpg 9 Aug 18 11:30 2002handbook.php -> index.php -rw-r--r-- 1 123284 tpg 80348 Aug 18 11:31 2003handbook.html lrwxr-xr-x 1 123284 tpg 9 Aug 18 11:30 2003handbook.php -> index.php -rw-r--r-- 1 597297 tpg 10776 Aug 18 11:32 alumni.html lrwxr-xr-x 1 123284 tpg 9 Aug 18 11:30 alumni.php -> index.php -rw-r--r-- 1 123284 tpg 1048 Aug 18 11:31 application.html lrwxr-xr-x 1 123284 tpg 9 Aug 18 11:30 application.php -> index.php -rw-r--r-- 1 597297 tpg 8271 Aug 18 11:30 faculty.html lrwxr-xr-x 1 123284 tpg 9 Aug 18 11:30 faculty.php -> index.php lrwxr-xr-x 1 123284 tpg 13 Jul 12 10:25 index.html -> overview.html -rw-r--r-- 1 123284 tpg 360 Aug 18 11:29 index.php -rw-r--r-- 1 123284 tpg 3458 Aug 18 11:31 overview.html -rw-r--r-- 1 597297 tpg 1671 Aug 18 11:32 students.html lrwxr-xr-x 1 123284 tpg 9 Aug 18 11:30 students.php -> index.php

In this case there is really only one PHP file (index.php). All the other PHP files are simple symlinks to it. This sole PHP file is as simple as one can want:

<?php $SWSURL = '/sws'; $SWSDIR = $_SERVER['DOCUMENT_ROOT'] . $SWSURL; // Where all my files are include_once "$SWSDIR/common.php"; session(); do_page(); ?>

Use One PHP Program to Show Various HTML Files

In this case we write a slightly more complex PHP program which supports a parameter file=name which specifies the name of an HTML file (no '/' allowed) to be read and displayed:

<?php /*################################################################# # Syntax: showme.php?file=tom #################################################################*/ $SWSURL = '/sws'; $SWSDIR = $_SERVER['DOCUMENT_ROOT'] . $SWSURL; // Where all my files are include_once "$SWSDIR/common.php"; session(); // Watch for authorization to expire extract(isolate_parms('file')); // Get 'file' parameter $html = findfile($file); // Get $file.HTML $title = 'Show some Page of HTML'; // Use this title do_page($title,$html); // or use <!-- TITLE in $file.HTML ?>

Of course you can use more elaborate PHP code to construct the page of HTML to show. I've only shown you a very simple and probably insecure example.

I Need a More Complex Footer

The default footer for a page is pretty simple. Based on values in the local_config.php file, it contains the name of the web site, a copyright statement and a contact Email address. If the variable $REVISIONDATE was set, this will also show the date the file was last modified.

You might want a more elaborate footer or need it to vary based on the particular files being shown or who is viewing the document. All this can be programmed into your PHP program. Simply set the global variable $FOOTER and this will replace the SWS default as shown here:

<?php /*################################################################# # Syntax: showme.php?file=tom # Provide my own FOOTER #################################################################*/ $SWSURL = '/sws'; $SWSDIR = $_SERVER['DOCUMENT_ROOT'] . $SWSURL; // Where all my files are include_once "$SWSDIR/common.php"; session(); // Watch for authorization to expire extract(isolate_parms( 'file')); // Get 'file' parameter $html = findfile($file); // Get $file.HTML $FOOTER =<<<END <hr size="4" width="80%" noshade="noshade"> <p class="footer" align="center"> From <a href="index.php" class="footer"> <i>The Glied(t)s 1723-1993 and Poeppelmeiers 1804-1993</i></a> by <i>Donna Budzier</i>, Copyright (c)1993. <a href="index.php?file=copyright" class="footer">All rights reserved</a>. <br>Direct comments or questions to <a href="mailto:tpg@hps.com?subject=270" class="footer">tpg@hps.com</a> $REVISIONDATE</p> END; do_page('',$html); // Title found in HTML file ?>

Copyright

SWS is copyrighted by Terry Gliedt and the University of Michigan (2004-2012) and is available as free software. Neither the author nor the University provides any warranty this code is useful for any purpose. You may redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; See http://www.gnu.org/copyleft/gpl.html.


Simple Website Software (SWS)
$RCSfile: index.html,v $
$Date: 2012/05/14 15:11:20 $
$Revision: 1.8 $