Download presentation
Presentation is loading. Please wait.
Published byErnest Prosper Quinn Modified over 9 years ago
1
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) Instructor: Joseph DiVerdi, Ph.D., M.B.A.
2
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Examples Web Clock Changes from one viewing to another
3
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Examples Simple Survey
4
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Examples Simple Game
5
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Examples Quiz
6
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Examples Search Engine
7
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Examples Database access
8
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Overview CGI stands for Common Gateway Interface –It is a Specification Which Permits The Web Server Program to Communicate With Other Programs That Are Running On The Server Web Server Only Knows How to Serve Up HTML Pages CGI Enables Server to Interact With Other Programs
9
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Overview Operation is as follows: –Client Requests a Document –Server Recognizes That Document is a Program –Server Executes Program Supplies Data to Program Obtained From Client Request –Server Receives Program Output –Server Returns Document to Browser –Client Renders Document
10
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Dynamic Image Inclusion Digital Clock Demo
11
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Examples Web Clock Changes from one viewing to another
12
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Overview There are Few Restrictions on What Programming Language is Used in CGI Programs Perl, Java, Visual Basic, AppleScript, Shell, C++,... Perl is the Most Popular Language In Use CGI Defines The interface Between The Web Server & The Program –In Both Directions Web Server --> Program Program --> Web Server
13
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI In Brief
14
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Uses of CGI Page Serving is Not Limited To Previously Written Documents Web Pages Can Created On-The-Fly –Can Be Based on The Viewer's Input Collect Viewer Comments Respond to Responses
15
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Dynamic Page Content Page Created Dynamically Via CGI Program Page With Server Side Includes (SSI) Page With Embedded Call to CGI Program –The Result is Still an HTML Page –Viewer's Browser Just Sees HTML –CGI Interaction is Behind The Scenes
16
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Database Interaction Web Interface to Relational Database Management System (RDBMS) CGI Program is Required to –Decode Viewer Input –Assemble Query –Send Query to Database –Process Data Returned From Database –Create Return HTML Document
17
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Gateway to a Database
18
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Setting Up For CGI Programs Create cgi directory in html directory –CaSe iS vErY iMpOrTaNt! Ensure cgi directory has 755 permission Programs must be placed in this directory –Server is configured only to execute from there Programs placed in and viewed from other directories will not execute and the program contents will be rendered on the browser
19
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Using CGI Programs Ensure CGI programs have 755 permission Always test program with telnet client FIRST! –Login to your account –Navigate to the html/cgi directory –Check if the program executes successfully env.cgi Then test using Browser http://linus.ulltra.com/~my_account/cgi/env.cgi
20
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Simple Shell Program Create a file "env.cgi" #! /bin/sh echo "Content-type: text/html" echo env Remember... –CGI programs can be written in many languages
21
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Simple But Useful Program Create a file "simple.pl" #! /usr/bin/perl -w print "Content-type: text/html\n\n"; print "Hello, CGI Programmer! "; exit; Save file in cgi directory Ensure program has 755 permission Test using telnet client Test using browser
22
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC More Useful Program Modify the file "simple.pl" #! /usr/bin/perl -w print "Content-type: text/html\n\n"; print "Hello, CGI Programmer! "; print "The current time is ", scalar localtime, " "; print "You are using the computer: ", $ENV{'REMOTE_HOST'}, " "; exit;
23
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Form Processing Client Requests a Form
24
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Form Processing Client Renders Form
25
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Form Processing Viewer Fills in Form Client Sends Form to Server
26
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Form Processing Client Sends Data to Server –Uses POST Method in HTTP Request POST /cgi/formmail.pl HTTP/1.0 Host: xtrsystems.com... more headers here... ice_cream_flavor=chocolate
27
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Form Processing Server Recognizes URL –URL Points to CGI Program It knows because of the directory in the URL /cgi/formmail.pl Server Executes Program –Supplies Form Data to Program Form Data Received From POST Request "ice_cream_flavor=chocolate"
28
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI In Brief
29
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Form Processing Program Performs Some Work –Some Combination of the Following Stores Submitted Data in Database Creates e-mail Message From Submitted Data –Always Does This Creates HTML Thank You Page Sends Program Output to Server –HTML Thank You Page is Program Output
30
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI Form Processing Server Sends HTML Document to Browser Client Renders HTML
31
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC CGI and Form Processing
32
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Executing CGI Programs CGI Programs Are Just Like Other Resources –Can Reside on Your Host The Host With the Server –Can Reside on Some Other Host With the Owner's Agreement Without the Owner's Agreement Unlike Other Resources –Must Reside in Specific Directories on Each Host Directory Selected by Webmaster or Site Administrator –Much Harder to Write than HTML Documents
33
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Hands On Work Create an Ice Cream Survey Form Page –Include the following HTML: You are using the formmail program –Executing On the xtrsystems.com Server Host
34
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Using Your own Programs Install formmail.pl in Your Own Account –Download From Course Materials Page –Upload to cgi Directory –Check Program Permission –Modify Form HTML –Test as Described Earlier –Modify Program Be Very Careful –Have Fun
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.