1 / 22

Server Side Includes and cgi scripts

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 .

rollo
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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced Web Programming Server Side Includesand cgi scripts

  2. 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: -->

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

  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. 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. include • 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”-->

  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. 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. echo • echo command used to output CGI environmental variables and SSI var <!--#echo var=“LAST_MODIFIED”-->

  10. echo • To create a back button, use echo with the HTTP_REFERER environment variable <a href=“<!--#echo var=‘HTTP_REFERER’-->”>Back Button</a>

  11. config • 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” -->

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

  13. exec • 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”-->

  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): <body> <!--#include file=”head.shtml"--> <h1>Test 3</h1> … <p> <!--#config timefmt="%d/%m/%y" --> <!--#echo var="DATE_LOCAL" --> </body> </html>

  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. Mailmerge.cgi • Files needed for mailmerge • The HTML form • Mailmerge.cgi • A template file • A results file

  17. 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 Mailmerge.cgi exSurvey.template Mailmerge.cgi exSurvey.html Web Server exForm.html internet

  18. 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”

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

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

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

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

More Related