CGI. CGI Programming What is "CGI"? –Common Gateway Interface A means of running an executable program via the Web. CGI is not a Perl-specific concept.

Slides:



Advertisements
Similar presentations
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Advertisements

Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
CGI Programming.
Lecture 14 HTML Forms CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
JavaScript Forms Form Validation Cookies CGI Programs.
CS 898N – Advanced World Wide Web Technologies Lecture 6: PERL and CGI Chin-Chih Chang
1 Web Search Interfaces. 2 Web Search Interface Web search engines of course need a web-based interface. Search page must accept a query string and submit.
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
Definitions, Definitions, Definitions Lead to Understanding.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
Common Gateway Interface
1 ‘Dynamic’ Web Pages So far, we have developed ‘static’ web-pages, e.g., cv.html, repair.html and order.html. There is often a requirement to produce.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Internet / Intranet Fall 2000 Class 7. Brandeis University Internet/Intranet Spring Class 7 Agenda Project / Homework Discussion Forms Validating.
Internet / Intranet CIS-536 Class 7. 2 HTML Forms A Method to Allow Users to Pass Information to a CGI Script Forms Allow Information to Be Entered Via:
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
JavaScript, Fourth Edition
Python CGI programming
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
Introduction to Programming the WWW I CMSC Summer 2004 Lecture 6.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
USING PERL FOR CGI PROGRAMMING
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: HTTP and CGI Fundamentals of Web Programming.
Chapter 8 Cookies And Security JavaScript, Third Edition.
10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
Website Development with PHP and MySQL Saving Data.
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.
Chapter 6 Server-side Programming: Java Servlets
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
Perl CGI What is "CGI"? Common Gateway Interface A means of running an executable program via the Web. Perl have a *very* nice interface to create CGI.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
HTML Form Widgets. Review: HTML Forms HTML forms are used to create web pages that accept user input Forms allow the user to communicate information back.
Form Data Encoding GET – URL encoded POST – URL encoded
Netprog 2002 CGI Programming1 CGI Programming CLIENT HTTP SERVER CGI Program http request http response setenv(), dup(), fork(), exec(),...
Saving State on the WWW. The Issue  Connections on the WWW are stateless  Every time a link is followed is like the first time to the server — it has.
Jan 2001C.Watters1 World Wide Web and E-Commerce Client Side Processing.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
+ FORMS HTML forms are used to pass data to a server. begins and ends a form Forms are made up of input elements Every input element has a name and value.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Netprog CGI and Forms1 CGI and Forms A detailed look at HTML forms.
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
HTML Forms.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
Introduction to CGI PROG. CGI stands for Common Gateway Interface. CGI is a standard programming interface to Web servers that gives us a way to make.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
Lesson 11. CGI CGI is the interface between a Web page or browser and a Web server that is running a certain program/script. The CGI (Common Gateway Interface)
How to Write Web Forms By Mimi Opkins.
Lesson 6: Web Forms.
Presentation transcript:

CGI

CGI Programming What is "CGI"? –Common Gateway Interface A means of running an executable program via the Web. CGI is not a Perl-specific concept. Almost any language can produce CGI programs –even C++ (gasp!!) However, Perl does have a *very* nice interface to creating CGI methods

Common Gateway Interface User selects page that will be provided by a CGI application Server recognizes dynamic page –By extension (usually.cgi) –By location Server spawns the app –Passes message body via stdin –HTTP header info available in environment variables App passes HTML page back to server via stdout Server sends page back to user

CGI Advantages –Original approach (substantial installed base) –Use any language compatible with or available on the server –Many free CGI scripts ( Disadvantages –Overhead of spawning/killing the app repeatedly –Concurrent hits on page cause multiple parallel copies of the app in memory file sharing, etc. –Many CGI scripts use slow interpreted languages Many use PERL

Web Server Architecture Client CGI program stdin stdout http Socket Queue connect newSkt Web Server // Server pseudo code // Create Socket Queue // Create Thread pool while(1) { newSkt = accept(…) EnQ(newSkt) } // Thread pseudo code while(1) { newSkt = DeQ() // Communicate // using HTTP }

GET vs. POST POST /path/script.cgi HTTP/1.0 From: User-Agent: HTTPTool/1.0 Content-Type: application/x-www-form-urlencoded Content-Length: 32 home=Cosby&favorite+flavor=flies GET /path/file.html?n=v HTTP/1.1 Host: [blank line here]

CGI & Parameters All input to a CGI program comes from: –EnvironmentHTTP headers –stdinMessage Body Get –Query string - Everything after the ? Goes in environment variable QUERY_STRING POST –All data comes in the message body via stdin - just read and parse appropriately

Launching CGI void LaunchCGI { //create pipes fork() if (child) { //allocate and setup the environment variable array //fill env array with HTTP headers //format HEADER_NAME=header value //use dup2 to duplicate the pipes onto stdin & stdout exec } else { // Write the body of the HTTP message on the child’s stdin pipe // Read the headers sent back on the child’s stdout pipe // Parse out the Content-Length // Send the appropriate response line // Forward the headers on to the client on the socket // Read Content-Length bytes from child’s stdout pipe // Write Content-Length bytes to client on socket // close the pipes // wait on the child – waitpid // close the socket } void LaunchCGI { //create pipes fork() if (child) { //allocate and setup the environment variable array //fill env array with HTTP headers //format HEADER_NAME=header value //use dup2 to duplicate the pipes onto stdin & stdout exec } else { // Write the body of the HTTP message on the child’s stdin pipe // Read the headers sent back on the child’s stdout pipe // Parse out the Content-Length // Send the appropriate response line // Forward the headers on to the client on the socket // Read Content-Length bytes from child’s stdout pipe // Write Content-Length bytes to client on socket // close the pipes // wait on the child – waitpid // close the socket }

Forms –Most (not all) CGI scripts are contacted through the use of HTML forms. –A form is an area of a web page in which the user can enter data, and have that data submitted to another page. –When user hits a submit button on the form, the web browser contacts the script specified in the form tag.

Creating a Form... Method attribute specifies how parameters are passed –"post" means they’re passed in the HTTP header and message body (and therefore aren’t seen on the browser address bar). –"get" means they’re passed through the query string of the URL itself, and therefore seen in the address bar in the web browser (given to CGI program in the QUERY_STRING header). –Action attribute specifies which program you want the web browser to contact. – is a tag used to accept User data. –type="submit" specifies a Submit button. When user clicks this button, browser contacts file specified in action attribute.

Form Input Types –Many different ways of getting data from user. Most specified by tag, type specified by type attribute textfield a text box checkbox a check box radio a Radio button password password field (text box, characters display as ******) Hidden - hidden field (nothing displayed in browser) Submit - Submit button. Submits the form Reset - Reset button. Clears form of all data. Button - A button the user can press (usually used w/ javaScript. File - field to upload a file Image - an image user can click to submit form

Preserving State in CGI

Preserving State HTTP is stateless, but we would like to save and remember state –Shopping cart –Interactive or multipart questionnaire –A search engine that remembers past searches Main techniques –Hidden fields –URL rewriting –Cookies –Session ID

Hidden Fields Add hidden input fields to a form – Advantages –Easy Disadvantages –Data is continually sent back and forth –Data is easily readable & changeable –Only available if there is a form

URL Rewriting Create links dynamically –Contain information in the url – Advantages –Fairly simple also Disadvantages –If state is complex, must encode –User visible and modifiable

Cookies A small piece of information stored on the client machine and returned to the server. Implemented using HTTP headers –Cookie –Set-Cookie 4 K bytes per cookie 20 cookies per server or domain at least

Set-Cookie (server side) Set-Cookie: name=value - URL encoded text [;EXPIRES=dateValue] - Wdy, DD-Mon-YY HH:MM:SS GMT [;DOMAIN=domainName] - valid domain name [;PATH=pathName] - path to send cookie [;SECURE] - transmitted only if communication is SSL

Cookie (client-side) Cookie: name=value1; name=value2 All cookie name=value pairs that match the current path are sent.

Details Browser GET /index.html HTTP/1.1 Host: Server HTTP/ OK Content-type: text/html Set-Cookie: name=value Set-Cookie: name2=value2; Expires=Wed, 09 Jun :18:14 GMT Browser GET /spec.html HTTP/1.1 Host: Cookie: name=value; name2=value2 Accept: */*

Session ID Generate a session ID –use as filename or DB key – store session info –Large random number –Time, PID, etc. Pass the session ID using url rewriting or hidden fields or cookies –More secure because user can only change the session ID and most likely will be wrong Advantages –Good when state is large, complex, or private –Easy using CGI.pm

SessionID example $query = new CGI; … open(FILE, “>$sessionID.sav”) || die “…”; $query->save(FILE); close(FILE) $query = new CGI; … open(FILE, “>$sessionID.sav”) || die “…”; $query->save(FILE); close(FILE) $cgi = new CGI; … open(FILE, “$sessionID.sav”) || die “…”; $oldquery = new CGI(FILE); close(FILE) $cgi = new CGI; … open(FILE, “$sessionID.sav”) || die “…”; $oldquery = new CGI(FILE); close(FILE) Note: You can also use a database – We will cover this in the lab