Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Server Side Includes and cgi scripts Advanced Web Programming.

Similar presentations


Presentation on theme: "1 Server Side Includes and cgi scripts Advanced Web Programming."— Presentation transcript:

1 1 Server Side Includes and cgi scripts Advanced Web Programming

2 2 Server Side Includes SSI Use to add text or html to a page from another file Format of SSI: 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: -->

3 3 Server Side Includes SSI 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.

4 4 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

5 5 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.

6 6 include Use the file parameter if the file is in the same directory Use the virtual parameter if the file is in a different directory

7 7 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

8 8 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 "\".

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

10 10 echo To create a back button, use echo with the HTTP_REFERER environment variable ”>Back Button

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

12 12 config Other format codes see: http://bignosebird.com/sdocs/echo.shtml

13 13 exec Exec command used to place the output of a program in an HTML page. –The program is usually a cgi program

14 14 Example This is an example of a SSI that works on arnor: http://arnor.ithaca.edu/~barr/testSSI.shtml The code (the included file is in the same directory): Test 3 …

15 15 Mailmerge.cgi Mailmerge is a program that –receives input from a web form, –Formats the input according to a template –Stores the input in a file

16 16 Mailmerge.cgi Files needed for mailmerge –The HTML form –Mailmerge.cgi –A template file –A results file

17 17 Mailmerge.cgi exForm.html internet Web Server Mailmerge.cgi exSurvey.template exSurvey.html Info sent to web server web server starts mailmerge and gives it info mailmerge looks at template file to format info mailmerge formats info and stores in results.txt

18 18 Mailmerge Step 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” 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

19 19 Mailmerge Step 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.

20 20 Mailmerge ACTION=File:/~barr/exSurvey.html REQUIRED= name,year,major OUTPUT_FORM= Survey Results from @name@: Year: @year@ Major: @major@ Interests: @interests@ Other information Something interesting about me: @aboutMe@ Prefered email address:: @email@ ************************************************** 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.

21 21 Mailmerge Step 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

22 22 Mailmerge -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 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.


Download ppt "1 Server Side Includes and cgi scripts Advanced Web Programming."

Similar presentations


Ads by Google