Download presentation
Presentation is loading. Please wait.
Published byBeatrice Della Lambert Modified over 9 years ago
2
Overview A plain HTML document is static A CGI program is executed in real-time, so that it can output dynamic information. CGI (Common Gateway Interface) is the language or protocol that the browser uses to communicate the data from the form to the web server. A standard for interfacing external applications with information servers, such as HTTP or Web servers.
3
When the user submits his/her answers on a form, the browser bundles them up and sends them to the web server, which passes them on to your CGI script/program for processing. –The web page itself does not process the data entered on the form. Neither does the web server. A CGI script/program is any program which knows how to read that bundle of data. –The script/program must build up and return the html source for a web page –Shell and Perl scripts are easier and are more commonly used for CGI scripts.
4
CGI specification Define how these data are passed from the server to the gateway program, and vice versa
5
Script Web server CGI program Client Form Relative Programs and Files
6
... CGI program: /cgi-bin/php.cgi Script program: /~jlwang/php/test.html... CGI program: /cgi-bin/pw.pl
7
Script Web server Client Form Window based Structures HTTPODBC.DLL
8
... Script program: test.idc
9
Most gateway program are Scripts C, perl, shell Execution speed is often not an important factor The slowest part is the resource end
10
Communication with gateway programs Client to Server –URL query string –Extra path information in the URL –Message body (in HTML Forms) Server to Gateway program –Command-line argument –Standard input –Environment variables Gateway program to Server –Standard output
11
Client to Server URL query string –http://www.mcu.edu.tw/cgi-bin/ex_prog?query_info –Pass the query string query_info to the server –The server launches the gateway program ex_prog and passes it the query string Extra path information in the URL –http://www.mcu.edu.tw/cgi-bin/ex_prog/dir/file?query_info –/dir/file: extra path information –Pass information using environment variables Message body –HTTP POST method within HTML FORM –Pass information using standard I/O
12
Server to Gateway program Command-line argument –GET method within ISINDEX query Standard input –POST method Environment variables –Everything sent by the client, except POST data –The query string –The extra path information –The request header
13
Gateway program to Server Standard output –The only way that gateway programs can pass data to a client –Two parts A collection of server directives –Be used to compose the response header The data
14
CGI Environment Variables Server CGI About the Server Request-Specific Variables About the user
15
Server CGI The server uses command line arguments as well as environment variables. These environment variables are set when the server executes the gateway program.
16
About the Server SERVER_SOFTWARE –The name and version of the information server software answering the request (and running the gateway). Format: name/version SERVER_NAME –The server's hostname, DNS alias, or IP address as it would appear in self-referencing URLs. GATEWAY_INTERFACE –The revision of the CGI specification to which this server complies. Format: CGI/revision
17
Request-Specific Variables SERVER_PROTOCOL –The name and revision of the information protcol this request came in with. –Format: protocol/revision (HTTP:1.0) SERVER_PORT –The port number to which the request was sent. REQUEST_METHOD –The method with which the request was made. For HTTP, this is "GET", "HEAD", "POST", etc. PATH_INFO –The extra path information, as given by the client.
18
PATH_INFO –The extra path information, as given by the client. PATH_TRANSLATED –The server provides a translated version of PATH_INFO, which takes the path and does any virtual-to-physical mapping to it. –http://www.mcu.edu.tw/cgi/cgiprogram.cgi/x/y/z –(Assume the document root path:/home1/www/docs) PATH_INFO = /a/b/c PATH_TRANSLATED = /home1/www/docs/x/y/z SCRIPT_NAME –A virtual path to the script being executed, used for self-referencing URLs.
19
QUERY_STRING –The information which follows the ? in the URL which referenced this script. –http://www.mcu.edu.tw/cgi/test.cgi?mcu.edu.tw –QUERY_STRING= mcu.edu.tw AUTH_TYPE –The protocol-specific authentication method used to validate the user.
20
REMOTE_USER –If the server supports user authentication, and the script is protected, this is the username they have authenticated as. REMOTE_IDENT –Remote user name retrieved from the server. Usage of this variable should be limited to logging only. CONTENT_TYPE –For queries which have attached information, such as HTTP POST and PUT, this is the content type of the data. CONTENT_LENGTH –The length of the said content as given by the client.
21
About the user HTTP_ACCEPT –The MIME types which the client will accept, as given by HTTP headers. –Format: type/subtype, type/subtype HTTP_USER_AGENT –The browser the client is using to send the request. –Format: software/version library/version. REMOTE_HOST –Domain name of the user REMOTE_ADDR –IP address of the user
22
CGI: Output Standard output –Document generated by the script –Instructions to the server Scripts return –Output a document to their standard output –Output the location of the result document (either a full URL or a local virtual path) The server normally adds the needed HTTP headers to the back-end's results
23
Data stream –Header One or more lines of text, and is separated from the body by a blank line –Body Contains MIME-conforming data whose content type must be reflected in the header The server does not interpret or modify the body in any way
24
CGI Output Example print <<EOT; Content-type: text/html Search Results Search Results EOT
25
Examples
26
CGI and Database
27
Gateway Program
28
Database Interface Gateway program transfers the received data into the database query, which then is passed to database interface. Database interface parses the received database query
29
Database Server Database interface passes the query to the database server After handling the query, the database server feed the query result back to the database interface
30
Local Database Server The database server and the Web server are in the same site
31
Remote Database Server (homogeneous)
32
Remote Database Server ( heterogeneous )
33
Third party model Database independent
34
Report 3 ASAP WebShow 1,3,4 CyberGo 5,7,8 Look@Me 9,10,11 EarthgTime 12,13,14 Crescendo ActiveX Control 31,32,33 EchoSpeech 34,35,36 EchoSpeech Real Time Broadcast 38,39,40 Koan ActiveX Control 41,43,44 MidPlug 45,46,47 RapidTransit Player 48,49,50 RealAudio Player 52,53,54 Shockwave Audio 55,56,57 ToolVox PlugIn 58,60,61 TrueSpeech PlugIn 62, 66 WebTracks PlugIn 67, 69 Surround Video 15,16,17 VDOLive Video 18,19,20 VivoActive Video 21,22,23 MhAVI Video 24,25,26 ActiveMovie Video 28, 29,30
35
Home1 Personal Home Page Home2 Calculator ( HTML Control ) Home3Transparency Show ( Multiple Frame ) Home4 Chess ( ActiveX ) Home5Credit Card ( VBScript ) Home6 Cookie (Cookie) Home7Student Query System (IDC) Home8Teaching Schedule Transformation (PERL) Report1 ActiveX-1 Report2 ActiveX-2 Report3 ActiveX-3 Report4ActiveX-4
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.