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.

Slides:



Advertisements
Similar presentations
CGI & HTML forms CGI Common Gateway Interface  A web server is only a pipe between user-agents  and content – it does not generate content.
Advertisements

The Web Warrior Guide to Web Design Technologies
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
CGI Programming Part 2. Input Tags Many different ways of getting data from the user. The tag is used most often. has a type attribute –Specifies the.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
How does the server format the information it gives to the appln program? As environment variables and in standard input.
What is CGI? The Common Gateway Interface (CGI) is a mechanism that allows Web clients to execute programs on a Web server and to receive their output.
Python and Web Programming
Guide To UNIX Using Linux Third Edition
Outcomes Know what are CGI Environment Variables Know how to use environment variables How to process A simple Query Form Able to use URL Encoding rules.
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.
CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
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.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
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)
CP3024 Lecture 3 Server Side Facilities. Lecture contents  Server side includes  Common gateway interface (CGI)  PHP Hypertext Preprocessor (PHP) pages.
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.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
CP476 Internet Computing CGI1 CGI is a common way to provide for specific computations on server side, interactions with users, or access to databases.
Web Server Design Week 14 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 4/14/10.
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
CSU - DCE Advanced Perl CGI Operation - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) on the.
Java CGI Lecture notes by Theodoros Anagnostopoulos.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: HTTP and CGI Fundamentals of Web Programming.
CSCE Systems Programming Lecture 21 Web Server: CGI -Dynamic Pages CSCE March 25, 2013.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming.
Website Development with PHP and MySQL Saving Data.
Chapter 9: Perl and CGI Programming CGI Programming Acknowledgement: Some materials are taken from Teach Yourself CGI Programming with PERL 5 in a Week.
Chapter 6 Server-side Programming: Java Servlets
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
Approaches for creating dynamic web pages Server-side processing: Server receives a request, performs all processing necessary to create a dynamic web.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
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.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) Instructor: Joseph DiVerdi,
Form Data Encoding GET – URL encoded POST – URL encoded
Introduction to JavaScript CS101 Introduction to Computing.
Netprog 2002 CGI Programming1 CGI Programming CLIENT HTTP SERVER CGI Program http request http response setenv(), dup(), fork(), exec(),...
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
HTLM Forms CS3505. Form Handling in Browser html User Files out form WEbBROWSErWEbBROWSEr User read response submit Get URL?input html Get file html script.
Copyright © 2002 ProsoftTraining. All rights reserved. Java Servlets.
Jan 2001C.Watters1 World Wide Web and E-Commerce Client Side Processing.
Krerk Piromsopa. 1 Department of Computer Engineering. Chulalongkorn University. Web Application Generic Issues.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
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 Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
Web Server Design Assignment #5: Unsafe Methods & CGI Due: 05/05/2010 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin.
CS 330 Class 8 Homework A pattern that contains a word with an optional period A pattern that contains Fred with a space (not Freddy) See regexp.txt guest4.htm.
Web Server Design Week 13 Old Dominion University Department of Computer Science CS 495/595 Spring 2012 Michael L. Nelson 04/03/12.
Web Server Design Week 15 Old Dominion University Department of Computer Science CS 495/595 Spring 2009 Michael L. Nelson 4/20/09.
1 CGI (Common Gateway Interface) CmpE 587 Emir Bayraktar Onur Bük.
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)
1 The Internet Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
The Common Gateway Interface (CGI) Pat Morin COMP2405.
CSCE Systems Programming
Environment Variables
An Example of a TCP/IP Application: the World Wide Web
Web Server Design Week 16 Old Dominion University
Presentation transcript:

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 our sites dynamic and interactive. CGI is not a programming language. It is just a set of standards (protocols.) CGI can be implemented in an interpreted language such as PERL or in a compiled language such as C.

Introduction to CGI PROG. (continued) CGI programs work as follows: STEP 1: (On the client side): Get Information from the user (using HTML forms, Java Applet, …,etc). STEP 2: (On the server side): Process the data, connect to DATABASE, search for PATTERNS, …,etc. STEP 3 :(On the server side): Send the result of computation back to the client.

What Is CGI? The Common Gateway Interface (CGI) is a standard (protocol) for interfacing external applications with information servers, such as HTTP or Web servers. A CGI program is executed in real-time, so that it can output dynamic information. The Web server can call up a program, while passing user- specific data to the program. The program then processes that data and the server passes the program's response back to the Web browser.

Internal Working of CGI Typical setup All CGI programs are stored in one cgi-bin directory All CGI files have special extension (.pl,.cgi etc). The system must be set to execute these programs instead of returning the program itself.

Internal Workings of CGI(cont.) GET /cgi-bin/cgiwrap/martin/welcome.cgi HTTP/1.1 Host: cgi.csc.liv.ac.uk User-Agent: Mozilla/4.0 (compatible; Window xp professional) Connection: close Idea 3. Web servers: recognize it is a CGI program execute the program (welcome.cgi) makes user’s info available to the CGI program along with some server info Idea1. CGI programs: a special directory (e.g. a certain file extension (e.g pl, cgi) Idea 2. HTTP requests (GET, POST) specify URL (e.g. /cgi-bin/welcome.cgi) specify protocol (e.g. HTTP/1.1) specify user-agent (e.g. Mozilla/4.0) specify user’s data

Internal Workings of CGI (cont.) Idea 4. Input to CGI program from (STDIN) Idea 5. Output from CGI program STDOUT as a data stream Idea 6. Output as data stream HTTP header + a blank line + body if a complete HTTP header, to the client if not, the server must do it.

8 HTTP SERVER CGI Program stdin stdout Environment Variables

CGI PROCESSING ARCHITECTURE

Database Processing DATABSE PROCESSING THOUGH CGI GATEWAY WEB BROWSER Web Server CGI Gateway DBMS

Perl Basic Introducion The first line of a script is called the shebang line. It should look like this: #!/usr/bin/perl -w usr/bin/perl tells the system where the Perl interpreter is located. The -w switch tells the interpreter to turn on Warnings about possible problems with your code. This will help you with your debugging. In plain Perl, all you have to do to print something is use the print command. But with Perl CGI for the web you have to include this line before your first print command:

(continued) print "Content-type: text/html\n\n"; This is called an http header and tells the browser what kind of content it's about to get. If you don't include this then you'll get an Internal Server Error when you try to run it.

PERL Data Types PERL has three built-in data types: scalars, arrays of scalars, and associative arrays of scalars, known as "hashes". Scalar Variables A scalar may contain one single value in any of three different flavors: a number, a string, or a reference. Scalar values are always named with '$‘ at the beginning, even when referring to a scalar that is part of an array or a hash. Examples: $day #A simple scalar value "day" $day[28] #the 29th element

PERL Data Type (Continued) Array Variables An array is basically a way to store a whole bunch of scalar values under one name. An array name begins with an symbol. = ("element1", = ("NS", "IE", = (1, 2, 3);

PERL Data Type (Continued) Associative Arrays “Hashes” Associative arrays are created with a set of key/value pairs. A key is a text string of your choice that will help you remember the value later. A hash name begins with % sign. Examples: %hashName = ('key1', 'value1', 'key2', 'value2'); %ourFriends = ('best', 'Don', 'good', 'Robert', 'worst', 'Joe');

Getting the Input to CGI A CGI program may need the following information: Information about the client, the server, and the user, Form data that the user supplied, Additional pathname information. CGI get these information from the CGI environment variables (%ENV).

Environment Variables GATEWAY_INTERFACE SERVER_NAME SERVER_SOFTWARE SERVER_PROTOCOL SERVER_PORT REQUEST_METHOD PATH_INFO PATH_TRANSLATED SCRIPT_NAME DOCUMENT_ROOT QUERY_STRING REMOTE_HOST REMOTE_ADDR AUTH_TYPE REMOTE_USER REMOTE_IDENT CONTENT_TYPE CONTENT_LENGTH HTTP_ACCEPT HTTP_USER_AGENT Etc.

Accessing Form Input The CGI program can access the form input.

A Simple Form Can use a form to solicit the information from the user. Simple Form! Simple Form! Command: GET /cgi-bin/CGI07.cgi?command=fortune HTTP/1.1.. (header information). GET is the default "fortune" (or some other string) can be in the text field submit button is pressed The browser sends this request to the server

Request Method: Get GET requests can include a query string as part of the URL: GET /cgi-bin/CGI07.cgi?command=fortune Request Method Resource Name Delimiter Query String

/cgibin/CGI07.cgi?command=fortune The web server treats everything before the ‘?’ delimiter as the resource name In this case the resource name is the name of a program. Everything after the ‘?’ is a string that is passed to the CGI program.

GET Method Collect data through HTML Form, Include data in the request to web server, GET /cgi-bin/unix.pl?command=fortune HTTP/1.0 …. (header info) Get the data from the environment variable inside CGI: $query_string = $ENV{‘QUERY_STRING’};

Working with GET

Post Method Collect data through HTML Form, Submit data using POST POST /cgi-bin/unix.pl HTTP/1.0 … (header info) Content-length: 15 command=fortune CGI reads the input from the stadard input stream. $size_input = $ENV{‘CONTENT_LENGTH’}; read (STDIN, $input, $size_input);

HTML Form Structure Form Tag Action Attribute Field Method Attribute Field Input Tags Nested in Form Name & Type (what type of input control) Values / Bindings First name:

HTML Form Structure First name:

After Submit Button

Small Medium Large

Stoat Goat Weasel

red blue green purple … gray

Status Codes Status CodeMessage 200Success 204No Response 301Document Moved 401Unauthorized 403Forbidden 404Not Found 500Internal Server Error 501Not Implemented

Get vs. Post GET: CGI operations can be bookmarked It is known that certain shells may pose a limit to the maximum size of environment variables so very long forms are truncated as a result if user refreshes, or clicks back button? Double Submit!,then problems may occurs

Get vs. Post POST: CGI operations cannot be bookmarked If user refreshes, or clicks back button, browser may display warning form data, having received by the Web server is directly piped to the standard input from which CGI applications can read.

CGI Applications HTML Form processing Gateway to database Document Generation

Conclusion World-Wide-Web model is much more powerful than it appears on the surface Easily integrated with existing applications Easy to add new functionality CGI model can do lots of things… Update files Link to corporate databases Specialized Applications

Q\A