1 / 30

CGI

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

wilmer
Download Presentation

CGI

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

  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. Relative Programs and Files Web server Client Script Form CGI program

  6. <Form Action=/cgi-bin/php.cgi/~jlwang/php/test.html> . . . </Form> CGI program: /cgi-bin/php.cgi Script program: /~jlwang/php/test.html <Form Action=/cgi-bin/pw.pl> . . . </Form> CGI program: /cgi-bin/pw.pl

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

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

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

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

  11. CGI Environment Variables • Server  CGI • About the Server • Request-Specific Variables • About the user

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

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

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

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

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

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

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

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

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

  21. CGI Output Example print <<EOT; Content-type: text/html <HTML> <HEAD> <TITLE> Search Results</TITLE> </HEAD> <BODY> <H1> Search Results </H1> EOT

  22. Examples

  23. CGI and Database

  24. Gateway Program

  25. Database Interface Database interface parses the received database query Gateway program transfers the received data into the database query, which then is passed to database interface.

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

  27. Local Database Server The database server and the Web server are in the same site

  28. Remote Database Server (homogeneous)

  29. Remote Database Server ( heterogeneous )

  30. Third party model Database independent

More Related