CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5%...

23
CGI CGI
  • date post

    20-Dec-2015
  • Category

    Documents

  • view

    213
  • download

    0

Transcript of CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5%...

Page 1: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

CGICGI

Page 2: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 2

Common Gateway Common Gateway InterfaceInterface

Georgia Tech 1995 Web Usage SurveyGeorgia Tech 1995 Web Usage Survey– Perl - 46.7%Perl - 46.7%– C - 12.5%C - 12.5%– Shell Scripts - 8.1%Shell Scripts - 8.1%– Tcl - Tool Commercial LanguageTcl - Tool Commercial Language– Visual BasicVisual Basic– JavaJava– C++C++– AppleScriptAppleScript

Page 3: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 3

Example Shell ScriptExample Shell Script

#!/bin/sh#!/bin/sh

#Filename: hello.sh.cgi#Filename: hello.sh.cgi

echo "Content-type: text/html"echo "Content-type: text/html"

echoecho

echo echo "<html><head><title>Hello!</title>"<html><head><title>Hello!</title></head>"</head>"

echo "<body> Hello World! </body> echo "<body> Hello World! </body> </html>"</html>"

Page 4: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 4

Hello World!Hello World! in Perl in Perl

#!/usr/bin/perl#!/usr/bin/perl

print "Content-type: text/html\n\n";print "Content-type: text/html\n\n";

print print "<html><head><title>Hello!</title> "<html><head><title>Hello!</title> </head> \n";</head> \n";

print "<body> Hello, World! </body> print "<body> Hello, World! </body> <html>\n";<html>\n";

Page 5: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 5

Hello World!Hello World! in C in C

#include <stdio.h>#include <stdio.h>

main( )main( )

{{

printf("Content-type: text/html\n\n");printf("Content-type: text/html\n\n");

printf("<html><head><title>Hello!</printf("<html><head><title>Hello!</title>title>

</head>\n");</head>\n");

printf("<body>Hello, printf("<body>Hello, World!</body><html>\n");World!</body><html>\n");

}}

Page 6: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 6

Environment Variables Environment Variables Using a Shell ScriptUsing a Shell Script

#!/bin/sh#!/bin/shecho Content-type: text/plainecho Content-type: text/plainechoecho

echo GATEWAY_INTERFACE = echo GATEWAY_INTERFACE = $GATEWAY_INTERFACE$GATEWAY_INTERFACE

echo REQUEST_METHOD = $REQUEST_METHODecho REQUEST_METHOD = $REQUEST_METHODecho SCRIPT_NAME = $SCRIPT_NAMEecho SCRIPT_NAME = $SCRIPT_NAMEecho QUERY_STRING = $QUERY_STRINGecho QUERY_STRING = $QUERY_STRINGecho SERVER_SOFTWARE = $SERVER_SOFTWAREecho SERVER_SOFTWARE = $SERVER_SOFTWAREecho SERVER_NAME = $SERVER_NAME echo SERVER_NAME = $SERVER_NAME echo SERVER_PROTOCOL = $SERVER_PROTOCOL echo SERVER_PROTOCOL = $SERVER_PROTOCOL echo SERVER_PORT = $SERVER_PORT echo SERVER_PORT = $SERVER_PORT echo HTTP_USER_AGENT = $HTTP_USER_AGENT echo HTTP_USER_AGENT = $HTTP_USER_AGENT echo HTTP_ACCEPT = $HTTP_ACCEPTecho HTTP_ACCEPT = $HTTP_ACCEPT

Page 7: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 7

Environment Variables Environment Variables Using a Shell ScriptUsing a Shell Script

echo PATH_INFO = $PATH_INFO echo PATH_INFO = $PATH_INFO echo PATH_TRANSLATED = echo PATH_TRANSLATED =

$PATH_TRANSLATED$PATH_TRANSLATEDecho REMOTE_HOST = $REMOTE_HOSTecho REMOTE_HOST = $REMOTE_HOSTecho REMOTE_ADDR = $REMOTE_ADDRecho REMOTE_ADDR = $REMOTE_ADDRecho REMOTE_USER = $REMOTE_USERecho REMOTE_USER = $REMOTE_USERecho REMOTE_IDENT = $REMOTE_IDENTecho REMOTE_IDENT = $REMOTE_IDENTecho AUTH_TYPE = $AUTH_TYPEecho AUTH_TYPE = $AUTH_TYPEecho CONTENT_TYPE = $CONTENT_TYPEecho CONTENT_TYPE = $CONTENT_TYPEecho CONTENT_LENGTH = $CONTENT_LENGTHecho CONTENT_LENGTH = $CONTENT_LENGTH

Page 8: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 8

Environment Variables in Environment Variables in PerlPerl

#!/usr/bin/perl#!/usr/bin/perlprint "Content-type: text/plain\n\n"print "Content-type: text/plain\n\n"

print "GATEWAY_INTERFACE = print "GATEWAY_INTERFACE = $ENV{'GATEWAY_INTERFACE'}\n"$ENV{'GATEWAY_INTERFACE'}\n"

print "REQUEST_METHOD = print "REQUEST_METHOD = $ENV{'REQUEST_METHOD'}\n"$ENV{'REQUEST_METHOD'}\n"

print "SCRIPT_NAME = $ENV{'SCRIPT_NAME'}\n"print "SCRIPT_NAME = $ENV{'SCRIPT_NAME'}\n"print "QUERY_STRING = $ENV{'QUERY_STRING'}\print "QUERY_STRING = $ENV{'QUERY_STRING'}\

n"n"print "SERVER_SOFTWARE = print "SERVER_SOFTWARE =

$ENV{'SERVER_SOFTWARE'}\n"$ENV{'SERVER_SOFTWARE'}\n"print "SERVER_NAME = $ENV{'SERVER_NAME'}\n" print "SERVER_NAME = $ENV{'SERVER_NAME'}\n" print "SERVER_PROTOCOL = print "SERVER_PROTOCOL =

$ENV{'SERVER_PROTOCOL'}\n"$ENV{'SERVER_PROTOCOL'}\n"

Page 9: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 9

Environment Variables in Environment Variables in PerlPerl

print "SERVER_PORT = $ENV{'SERVER_PORT'}\n"print "SERVER_PORT = $ENV{'SERVER_PORT'}\n"print "HTTP_USER_AGENT = print "HTTP_USER_AGENT =

$ENV{'HTTP_USER_AGENT'}\n"$ENV{'HTTP_USER_AGENT'}\n"print "HTTP_ACCEPT = $ENV{'HTTP_ACCEPT'}\n" print "HTTP_ACCEPT = $ENV{'HTTP_ACCEPT'}\n" print "PATH_INFO = $ENV{'PATH_INFO'}\n" print "PATH_INFO = $ENV{'PATH_INFO'}\n" print "PATH_TRANSLATED = print "PATH_TRANSLATED =

$ENV{'PATH_TRANSLATED'}\n"$ENV{'PATH_TRANSLATED'}\n"print "REMOTE_HOST = $ENV{'REMOTE_HOST'}\n"print "REMOTE_HOST = $ENV{'REMOTE_HOST'}\n"print "REMOTE_ADDR = $ENV{'REMOTE_ADDR'}\n"print "REMOTE_ADDR = $ENV{'REMOTE_ADDR'}\n"print "REMOTE_USER = $ENV{'REMOTE_USER'}\n"print "REMOTE_USER = $ENV{'REMOTE_USER'}\n"print "REMOTE_IDENT = $ENV{'REMOTE_IDENT'}\n"print "REMOTE_IDENT = $ENV{'REMOTE_IDENT'}\n"

Page 10: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 10

Environment Variables in Environment Variables in PerlPerl

print "AUTH_TYPE = $ENV{'AUTH_TYPE'}\n"print "AUTH_TYPE = $ENV{'AUTH_TYPE'}\n"

print "CONTENT_TYPE = print "CONTENT_TYPE = $ENV{'CONTENT_TYPE'}\n"$ENV{'CONTENT_TYPE'}\n"

print "CONTENT_LENGTH = print "CONTENT_LENGTH = $ENV{'CONTENT_LENGTH'}\n"$ENV{'CONTENT_LENGTH'}\n"

Page 11: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 11

Environment Variables in Environment Variables in CC

#include <stdio.h>#include <stdio.h>#include <stdlib.h>#include <stdlib.h>char *cp;char *cp;char *empty = "[empty]"char *empty = "[empty]"main( )main( ){{printf ("Content-type: text/plain\n\n");printf ("Content-type: text/plain\n\n");

#define safenv(a) ((cp = getenv(a)) ? cp : #define safenv(a) ((cp = getenv(a)) ? cp : empty)empty)

printf("GATEWAY_INTERFACE = %s\n", printf("GATEWAY_INTERFACE = %s\n", safenv("GATEWAY_INTERFACE"));safenv("GATEWAY_INTERFACE"));

Page 12: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 12

Environment Variables in Environment Variables in CC

printf("REQUEST_METHOD = %s\n", printf("REQUEST_METHOD = %s\n", safenv("REQUEST_METHOD"));safenv("REQUEST_METHOD"));

printf("SCRIPT_NAME = %s\n", printf("SCRIPT_NAME = %s\n", safenv("SCRIPT_NAME"));safenv("SCRIPT_NAME"));

printf("QUERY_STRING = %s\n", printf("QUERY_STRING = %s\n", safenv("QUERY_STRING"));safenv("QUERY_STRING"));

printf("SERVER_SOFTWARE = %s\n" printf("SERVER_SOFTWARE = %s\n" safenv("SERVER_SOFTWARE"));safenv("SERVER_SOFTWARE"));

printf("SERVER_NAME = %s\n", printf("SERVER_NAME = %s\n", safenv("SERVER_NAME"));safenv("SERVER_NAME"));

printf("SERVER_PROTOCOL = %s\n", printf("SERVER_PROTOCOL = %s\n", safenv("SERVER_PROTOCOL"));safenv("SERVER_PROTOCOL"));

printf("SERVER_PORT = %s\n", printf("SERVER_PORT = %s\n", safenv("SERVER_PORT"));safenv("SERVER_PORT"));

printf("HTTP_USER_AGENT = %s\n", printf("HTTP_USER_AGENT = %s\n", safenv("HTTP_USER_AGENT"));safenv("HTTP_USER_AGENT"));

Page 13: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 13

Environment Variables in Environment Variables in CC

printf("HTTP_ACCEPT = %s\n", printf("HTTP_ACCEPT = %s\n", safenv("HTTP_ACCEPT")); safenv("HTTP_ACCEPT"));

printf("PATH_INFO = %s\n", printf("PATH_INFO = %s\n", safenv("PATH_INFO")); safenv("PATH_INFO"));

printf("PATH_TRANSLATED = %s\n", printf("PATH_TRANSLATED = %s\n", safenv("PATH_TRANSLATED"));safenv("PATH_TRANSLATED"));

printf("REMOTE_HOST = %s\n", printf("REMOTE_HOST = %s\n", safenv("REMOTE_HOST"));safenv("REMOTE_HOST"));

printf("REMOTE_ADDR = %s\n", printf("REMOTE_ADDR = %s\n", safenv("REMOTE_ADDR"));safenv("REMOTE_ADDR"));

printf("REMOTE_USER = %s\n", printf("REMOTE_USER = %s\n", safenv("REMOTE_USER"));safenv("REMOTE_USER"));

Page 14: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 14

Environment Variables in Environment Variables in CC

printf("REMOTE_IDENT = %s\n", printf("REMOTE_IDENT = %s\n", safenv("REMOTE_IDENT"));safenv("REMOTE_IDENT"));

printf("AUTH_TYPE = %s\n", printf("AUTH_TYPE = %s\n", safenv("AUTH_TYPE"));safenv("AUTH_TYPE"));

printf("CONTENT_TYPE = %s\n", printf("CONTENT_TYPE = %s\n", safenv("CONTENT_TYPE"));safenv("CONTENT_TYPE"));

printf("CONTENT_LENGTH = %s\n", printf("CONTENT_LENGTH = %s\n", safenv("CONTENT_LENGTH"));safenv("CONTENT_LENGTH"));

}}

Page 15: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 15

Standard CGI VariablesStandard CGI Variables

User informationUser information– HTTP_USER_AGENTHTTP_USER_AGENT

Name and version of user's browserName and version of user's browser name/version library/versionname/version library/version Contains information about any proxy Contains information about any proxy

gatewaygateway– Used when firewalls existUsed when firewalls exist

Page 16: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 16

Standard CGI VariablesStandard CGI Variables

User informationUser information– HTTP_USER_AGENTHTTP_USER_AGENT

ExamplesExamples– Mozilla/2.0b1J (Windows; I; 32 bit)Mozilla/2.0b1J (Windows; I; 32 bit)– Mozilla/1.22 (Windows; I; 16 bit)Mozilla/1.22 (Windows; I; 16 bit)– Lynx/2.3.7 BETA libwww/2.14Lynx/2.3.7 BETA libwww/2.14– Microsoft Internet Explorer/4.40.308 (Windows Microsoft Internet Explorer/4.40.308 (Windows

95)95)

Page 17: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 17

Standard CGI VariablesStandard CGI Variables

User informationUser information– HTTP_ACCEPTHTTP_ACCEPT

Gives MIME formats that the browser can Gives MIME formats that the browser can acceptaccept

– REMOTE_HOSTREMOTE_HOST IP address of userIP address of user Always givenAlways given

– REMOTE_ADDRREMOTE_ADDR Text-equivalent host name of user IP addressText-equivalent host name of user IP address Not always givenNot always given

Page 18: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 18

Standard CGI VariablesStandard CGI Variables

Server informationServer information– SERVER_SOFTWARESERVER_SOFTWARE

Name and version of server softwareName and version of server software name/versionname/version

– Apache/0.6.4bApache/0.6.4b

– SERVER_NAMESERVER_NAME Server’s host name or IP addressServer’s host name or IP address

– www.cs.wayne.eduwww.cs.wayne.edu

– GATEWAY_INTERFACEGATEWAY_INTERFACE CGI revisionCGI revision

– CGI/CGI/revisionrevision– CGI/1.1CGI/1.1

Page 19: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 19

Standard CGI VariablesStandard CGI Variables

Request-specific informationRequest-specific information– QUERY_STRINGQUERY_STRING

Very importantVery important Most common method of passing Most common method of passing

information to serverinformation to server Suppose URL Suppose URL

http://www.cs.wayne.edu/cgi/code.cgi?x,y http://www.cs.wayne.edu/cgi/code.cgi?x,y is submittedis submitted

– All characters after the All characters after the ? ? will be put into will be put into QUERY_STRINGQUERY_STRING

Page 20: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 20

Standard CGI VariablesStandard CGI Variables

Request-specific informationRequest-specific information– SCRIPT_NAMESCRIPT_NAME

File name of the CGI program File name of the CGI program

– SERVER_PROTOCOLSERVER_PROTOCOL Name and revision of the protocol that Name and revision of the protocol that

request came in fromrequest came in from protocol/revisionprotocol/revision

– HTTP/1.0HTTP/1.0

Page 21: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 21

Standard CGI VariablesStandard CGI Variables

Request-specific informationRequest-specific information– SERVER_PORTSERVER_PORT

Port on which request came inPort on which request came in Usually 80Usually 80

– PATH_INFOPATH_INFO One can pass another file path to the CGI One can pass another file path to the CGI

program by appending it to the URLprogram by appending it to the URL http://www.cs.wayne.edu/cgi/cgi-http://www.cs.wayne.edu/cgi/cgi-

code.cgi/a/b/ccode.cgi/a/b/c– PATH_INFO will contain the extra path /a/b/cPATH_INFO will contain the extra path /a/b/c

Page 22: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 22

Standard CGI VariablesStandard CGI Variables

Request-specific informationRequest-specific information– PATH_TRANSLATEDPATH_TRANSLATED

Contains PATH_INFO appended to the Contains PATH_INFO appended to the document root path of the serverdocument root path of the server– /x/y/z/a/b/c/x/y/z/a/b/c

– CONTENT_TYPECONTENT_TYPE Used for queries that have attached Used for queries that have attached

information, such as POST requestsinformation, such as POST requests MIME content-type of dataMIME content-type of data type/subtypetype/subtype

– application/x-www-form-urlencodedapplication/x-www-form-urlencoded

Page 23: CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

XML 23

Standard CGI VariablesStandard CGI Variables

Request-specific informationRequest-specific information– CONTENT_LENGTHCONTENT_LENGTH

Number of bytes of dataNumber of bytes of data

– AUTH_TYPEAUTH_TYPE Contains authentication method used to Contains authentication method used to

validate uservalidate user

– REQUEST_METHODREQUEST_METHOD Method used for requestMethod used for request

– Usually either Usually either postpost or or getget