cgi programming. what is it? cgi –common gateway interface standard way to pass information back...

10
CGI Programming

Upload: primrose-flowers

Post on 03-Jan-2016

215 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: CGI Programming. What is it? CGI –Common Gateway Interface Standard way to pass information back to the Web Server –GET Query String –POST Standard Input

CGI Programming

Page 2: CGI Programming. What is it? CGI –Common Gateway Interface Standard way to pass information back to the Web Server –GET Query String –POST Standard Input

What is it?

• CGI– Common Gateway Interface

• Standard way to pass information back to the Web Server– GET

• Query String

– POST• Standard Input

Page 3: CGI Programming. What is it? CGI –Common Gateway Interface Standard way to pass information back to the Web Server –GET Query String –POST Standard Input

What is CGI?

• CGI is platform independent

• CGI is language independent

• Perl is the most popular development language

Page 4: CGI Programming. What is it? CGI –Common Gateway Interface Standard way to pass information back to the Web Server –GET Query String –POST Standard Input

CGI Environment

• CGI uses a subset of the OS environment for the application

• Can access native applications on server

• Runs as the server userid (normally)

• See showenv.pl

Page 5: CGI Programming. What is it? CGI –Common Gateway Interface Standard way to pass information back to the Web Server –GET Query String –POST Standard Input

CGI/HTML

• Data is passed to a CGI program from a HTML file with the Form tag– Method = GET– Method = POST

Page 6: CGI Programming. What is it? CGI –Common Gateway Interface Standard way to pass information back to the Web Server –GET Query String –POST Standard Input

Parsing Data

• If request is passed via GET, use QUERY_STRING environmental variable

• If request is passed via POST, you must read in the data from STDIN (the CONTENT_LENGTH environmental variable specifies how much data to read)

Page 7: CGI Programming. What is it? CGI –Common Gateway Interface Standard way to pass information back to the Web Server –GET Query String –POST Standard Input

Parse Some Data

• See advance.htm

• See simple_parse.pl

• See sample_cgipm.pl

Page 8: CGI Programming. What is it? CGI –Common Gateway Interface Standard way to pass information back to the Web Server –GET Query String –POST Standard Input

Form Verification

• Need to verify data before processing

• Bad data can be a security risk

• Assume all data is initially bad

• see verify.pl

• (In real life also use JavaScript )

Page 9: CGI Programming. What is it? CGI –Common Gateway Interface Standard way to pass information back to the Web Server –GET Query String –POST Standard Input

Cookies: State Management

• HTTP is stateless

• Cookies are the standard method for state management

• Can use hidden fields, mangled URLs, etc

• see cookie.htm

• see cookie.pl

• Cookies are not evil! :)

Page 10: CGI Programming. What is it? CGI –Common Gateway Interface Standard way to pass information back to the Web Server –GET Query String –POST Standard Input