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)

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming.
Advertisements

CGI & HTML forms CGI Common Gateway Interface  A web server is only a pipe between user-agents  and content – it does not generate content.
Adding Dynamic Content to your Web Site
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
Tutorial 6 Working with Web Forms
Week 2 IBS 685. Static Page Architecture The user requests the page by typing a URL in a browser The Browser requests the page from the Web Server The.
PZ15A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ15A - The Internet Programming Language Design and.
And so on CGI programming Web Services Java Programs for the Web.
CS 898N – Advanced World Wide Web Technologies Lecture 6: PERL and CGI Chin-Chih Chang
Python and Web Programming
1 CGI The Common Gateway Interface E-Commerce Prof. Sheizaf Rafaeli.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
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.
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.
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.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
XP Tutorial 6New Perspectives on HTML and XHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
ITIS 1210 Introduction to Web-Based Information Systems Chapter 24 How Websites Work with Databases How Websites Work with Databases.
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,
Server-side Scripting Powering the webs favourite services.
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.
Introduction to Programming the WWW I CMSC Summer 2004 Lecture 6.
USING PERL FOR CGI PROGRAMMING
Lecture # 6 Forms, Widgets and Event Handling. Today Questions: From notes/reading/life? Share Personal Web Page (if not too personal) 1.Introduce: How.
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.
Lecture 21 Common Gateway Interface CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
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.
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.
1 Basic Perl CGI Programming. 2 Issues How and when your program is invoked. Generating Response –HTTP Headers –HTML (or whatever document type you want)
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.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
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.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
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,
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.
Introduction to Programming the WWW I CMSC Winter 2003.
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.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
 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.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
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.
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.
1 CGI (Common Gateway Interface) CmpE 587 Emir Bayraktar Onur Bük.
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.
Chapter 7 - Introduction to Common Gateway Interface (CGI)
CGI I: Basics Web Programming.
An Example of a TCP/IP Application: the World Wide Web
CGI I: Basics Web Programming.
Presentation transcript:

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) is a way for a request to a web server to cause a program to execute, instead of just causing a static HTML page to be returned. The program that is run then dynamically generates a web page tag by tag, which is sent back to the browser that made the request.

CGI Perl is extremely powerful and well-suited to web programming, and is the language usually used with the CGI.

CGI A typical example would work like this; 1.The web user clicks the submit button of a simple form in which they have entered their first and last name. 2.The tag uses the get method, and the action

CGI  The form information is added to the URL as follows;  The http request is sent to the server.  Because the desired file ends with the.pl extension and is in the cgi-bin directory, the CGI causes the Perl interpreter to run the program called script1.pl.  When the CGI does this, it makes the form information (fname and lname in this case) available to the program as it executes

The browser contacts the server and requests a document. The server translates the URL into a path and file name. If the server finds out that the URL points to a program then –It prepares the environment and then runs the script. –The script executes and reads the environment variables and STDIN. –The script sends the proper headers to STDOUT for the forthcoming content and then it sends the rest of its output to STDOUT and terminates. –The server notices that the script has finished and closes the connection to your browser. Your browser displays the output from the script..

HTTP Request When an HTTP request is sent to a browser, it contains more information than just the details of the request.

Environment variables When CGI receives a request from a browser, it also gets a lot of other information. It makes this information available to your Perl programs in the form of a hash named %ENV.

Displaying the environment We can use a simple script to display the %ENV contents for our particular server, as shown by the following example

Get vs. Post Let’s take another look at the difference between get and post, this time from the server side.

Get We know that using get to submit a form appends the form contents to the url. This data is provided for us in the %ENV hash, under the key $QUERY_STRING.

Post On the other hand, the data sent by the post method is received via stdin, and must be processed differently

Handling post data The following example will show how we can obtain the data sent by the post method, and send it back to the user

Handling post data The first thing we have to do is get the form data from stdin. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); STDIN is a handle that refers to standard input. $buffer is an arbitrary variable that will hold the entire input string. CONTENT_LENGTH is the environmental value that lists how many bytes are being input.

Handling post data Once we have the input data in the variable $buffer, we can process it the same way that we processed the data in the previous example, using the split function to separate the parts of the string

get vs. post 1.#!/usr/bin/perl 2.print "Content-type:text/html\n\n"; 3.print " Form Output "; 4.print " Results from get method \n"; 5.print " "; = split(/&/,$ENV{'QUERY_STRING'}); 7.foreach $i { 8. ($varname, $mydata) = split(/=/,$i); 9. print " "; 10. $mydata =~ tr/+/ /; 11. $mydata =~ s/%([a-fA-F0-9][a-fA- F0-9])/pack("C", hex($1))/eg; 12. print "$varname = $mydata\n"; 13. print " "; 14.} 15.print " "; 16.print " "; 1.#!/usr/bin/perl 2.print "Content-type:text/html\n\n"; 3.read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); split(/&/, $buffer); 5.print " Form Output "; 6.print " Using post method \n"; 7.print " "; 8.foreach $i { 9.($name, $value) = split(/=/, $i); 10.$value =~ tr/+/ /; 11.$value =~ s/%([a-fA-F0-9][a-fA-F 0-9])/pack("C", hex($1))/eg; 12.print " "; 13.print $name, " = ", $value; 14.print " "; 15.} 16.print " "; 17.print " ";