Presentation is loading. Please wait.

Presentation is loading. Please wait.

CGI Scripts. 2 GET n Form data forms query string and is appended to the URL of the script –Can be accessed by using the environment variable QUERY_STRING.

Similar presentations


Presentation on theme: "CGI Scripts. 2 GET n Form data forms query string and is appended to the URL of the script –Can be accessed by using the environment variable QUERY_STRING."— Presentation transcript:

1 CGI Scripts

2 2 GET n Form data forms query string and is appended to the URL of the script –Can be accessed by using the environment variable QUERY_STRING –Browser or server may truncate data that exceeds an arbitrary number of characters

3 CGI Scripts3 GET n GET request by client GET /cgi-bin/prog.pl?name= Bill+age=29 HTTP/1.0 Accept: www/source Accept: text/html Accept: text/plain User-Agent: Lynx/2.4 libwww/2.14

4 CGI Scripts4 GET n Can access CGI program with a query without using a form CGI program CGI program n Can also send extra path information –Usually file name CGI program CGI program

5 CGI Scripts5 POST n Query length is unlimited n Script reads from standard input n Can't create canned queries

6 CGI Scripts6 POST POST /cgi-bin/prog.pl HTTP/1.0 Accept: www/source Accept: text/html Accept: text/plain User-Agent: Lynx/2.4 libww/2.14 Content-type: application/x-www- form-urlencoded Content-length: 22 user=Larry+Bird&age=30

7 CGI Scripts7 Decoding Form Data n Determine request protocol by checking the REQUEST_METHOD environment variable –GET or POST –One script can work for both methods n If the protocol is GET, read query string from QUERY_STRING and/or the extra path information from PATH_INFO

8 CGI Scripts8 Decoding Form Data n If the protocol is POST, determine the size of the request using CONTENT_LENGTH and read that amount of data from the standard input n Split the query string on the '&' character, which separates key-value pairs –The format is key=value&key=value...

9 CGI Scripts9 Decoding Form Data n Decode the hexadecimal and '+' characters in each key-value pair n Create a key-value table with the key as the index

10 CGI Scripts10 Examples n Using forms with POST –Plain text n Guestbook –http://jupiter.cs.wayne.edu/~grosky /user-cgi/guestbook.pl?add using the GET method, will present a form for you to enter information

11 CGI Scripts11 Examples n Guestbook –http://jupiter.cs.wayne.edu/~grosky /user-cgi/guestbook.pl using the GET method, will display the actual guestbook file [guestbook.htm] –Can open guestbook file directly by accessing http://jupiter.cs.wayne.edu/ ~grosky/CSC691/CGIScripts/ Guestbook/guestbook.htm

12 CGI Scripts12 Examples n Guestbook –When form is submitted using the POST method, this program decodes the information and outputs a thank-you message

13 CGI Scripts13 Examples n Survey –http://jupiter.cs.wayne.edu/~grosky /user-cgi/shopping.pl/start.htm –http://jupiter.cs.wayne.edu/ ~grosky/CSC691/CGIScripts/Hidden Fields/start.htm


Download ppt "CGI Scripts. 2 GET n Form data forms query string and is appended to the URL of the script –Can be accessed by using the environment variable QUERY_STRING."

Similar presentations


Ads by Google