Server side includes and cgi scripts
Sponsored Links
This presentation is the property of its rightful owner.
1 / 22

Server Side Includes and cgi scripts PowerPoint PPT Presentation

  • Uploaded on
  • Presentation posted in: General

Advanced Web Programming. Server Side Includes and cgi scripts. Server Side Includes SSI. Use to add text or html to a page from another file Format of SSI: <!--#command parameter=“argument”--> Note that extension of a page that uses SSI must be . shtml on arnor .

Download Presentation

Server Side Includes and cgi scripts

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

Advanced Web Programming

Server Side Includesand cgi scripts

Server Side IncludesSSI

  • Use to add text or html to a page from another file

  • Format of SSI:

    <!--#command parameter=“argument”-->

  • Note that extension of a page that uses SSI must be .shtml on arnor.

  • Note: no spaces between <!– and #

  • Closing bracket must be preceded by two dashes: -->

Server Side IncludesSSI

  • If a page that is included itself uses SSI (to display a date in a footer for example) the extension of that page must be .shtml on icsun.

SSI commands

  • include include another file in this file

  • echo print an environmental variable

  • exec place the output of a program in an html page

More SSI commands

  • fsize output the size of a file

  • config change the SSI error message, formatting time and file size information

  • flastmod displaying the last time a file was modified.


  • Use the file parameter if the file is in the same directory

    <!--#include file=“myFile.html”-->

  • Use the virtual parameter if the file is in a different directory

    <!--#include virtual=“/myDirect/myFile.html”-->

Environmental Variables

  • Variables that are maintained by the OS

  • SSI can output any CGI environmental variable

  • SSI can output 6 environmental variables specific to SSI

SSI environmental variables

  • DATE_GMT: holds date and time in GMT

  • DATE_LOCAL: holds date and time in local time zone

  • DOCUMENT_NAME: holds the current filename

  • DOCUMENT_URI: holds path of file from server root to filename

  • LAST_MODIFIED: holds last modification date and time for current file

  • QUERY_STRING_UNESCAPED: holds unaltered query string with all shell metacharacters escaped with a "\".


  • echo command used to output CGI environmental variables and SSI var

    <!--#echo var=“LAST_MODIFIED”-->


  • To create a back button, use echo with the HTTP_REFERER environment variable

    <a href=“<!--#echo var=‘HTTP_REFERER’-->”>Back Button</a>


  • You can use config to change the appearance of time and date using the timefmt variable before calling the date.

    <!--#config timefmt=“%m/%d/%y” -->


  • Other format codes see:


  • Exec command used to place the output of a program in an HTML page.

    • The program is usually a cgi program

      <!--#exec cgi=“/cgi-bin/myCGI.cgi”-->


  • This is an example of a SSI that works on arnor:


    The code (the included file is in the same directory):


    <!--#include file=”head.shtml"-->

    <h1>Test 3</h1>


    <!--#config timefmt="%d/%m/%y" -->

    <!--#echo var="DATE_LOCAL" -->




  • Mailmerge is a program that

    • receives input from a web form,

    • Formats the input according to a template

    • Stores the input in a file


  • Files needed for mailmerge

    • The HTML form

    • Mailmerge.cgi

    • A template file

    • A results file

mailmerge looks at template file to format info

mailmerge formats info and stores in results.txt

web server starts mailmerge and gives it info

Info sent to web server





Web Server



Note that this path wll be different if you put your form.html file in a directory (like ProbSet3). For every directory you go into, you must add another ../ to the path!

The same holds true here. If you put your survey.template file into a directory, you must add the directory name after the xxx in the path: cgi/home/xxx/public_html/exSurvey.template

MailmergeStep 1

  • Procedure for storing a form on a student account on arnor

    • Create the html form, for example exForm.html

      • In form tag, the action attribute must be

        action = "/cgi-bin/mailmerge.cgi/home/xxx/public_html/exSurvey.template”

MailmergeStep 2

  • Procedure for storing a form on a student account on arnor

    • Create the template, for example exSurvey.template

      • Can be in any directory and have any name,

      • but the action attribute of the form tag in the exForm.html file must point to it.

Path to file where results will be appended

Form elements that are required

The @ surround the name of a piece of data as given in the form.html file. The name will be substituted by the value of the name.

Any other text will appear in the file exactly as shown in the template file. You can even put in html tags.



REQUIRED= name,year,major


Survey Results from @name@:

Year: @year@

Major: @major@



<h2> Other information</h2>

Something interesting about me:


Prefered email address::



MailmergeStep 3

  • Procedure for storing a form on a student account on arnor

    • Create the exSurvey.html file

      • Can be in any directory, but the template must point to it.

      • Must ensure that the file has write permissions

Results.txt must have write permissions:

At the command line type:

chmod 666 exSurvey.html

where exSurvey.html is the name of the file that you are using.


-rw-r--r-- 1 jbarr other 3670 Aug 29 2002 form.html

-rw-r--r-- 1 jbarr other 1774 Oct 9 2002 form2.html

-rw-r--r-- 1 jbarr other 16752 Jan 24 2003 hp_4.jpe

-rw-r--r-- 1 jbarr other 214 Sep 10 2002 lab2.c

-rw-r--r-- 1 jbarr other 124 Aug 26 2002 local.cshrc

-rw-r--r-- 1 jbarr other 607 Aug 26 2002 local.login

-rw-r--r-- 1 jbarr other 582 Aug 26 2002 local.profile

-rwxr-xr-x 1 jbarr other 21468 Aug 29 2002 mailmerge.cgi

-rw-rw-rw- 1 jbarr other 2573 Sep 15 2003 exSurvey.html

drwxr-xr-x 2 jbarr other 512 Sep 13 2002 sbin

-rw-r--rw- 1 jbarr other 661 Aug 29 2002 survey.template

-rw-r--r-- 1 jbarr other 261 Sep 23 2002 testIn.c

-rwxr--r-- 1 jbarr other 167 Sep 3 2002 testScript

drwxr-xr-x 2 jbarr other 512 Mar 27 09:59 theLib

-rwxr-xr-x 1 jbarr other 1844 Oct 13 2002 turnIn2

-rw-r--r-- 1 jbarr other 2972 Sep 18 2003 xTest.shtml

  • Login