CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.

Slides:



Advertisements
Similar presentations
1 Copyright © 2002 Pearson Education, Inc.. 2 Chapter 1 Introduction to Perl and CGI.
Advertisements

Adding Dynamic Content to your Web Site
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
Server-Side vs. Client-Side Scripting Languages
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic Server Side Web Technologies: Part 2.
Active Server Pages Chapter 1. Introduction Understand how browsers and servers interacted when the Web was young Understand what early Internet and intranet.
Website Development with PHP and MySQL Introduction.
Guide To UNIX Using Linux Third Edition
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.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Web Client/Server Communication A290/A590, Fall /09/2014.
Chapter 6: Hostile Code Guide to Computer Network Security.
CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
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.
INTRODUCTION TO WEB DATABASE PROGRAMMING
JAVASCRIPT HOW TO PROGRAM -2 DR. JOHN P. ABRAHAM UTPA.
1 Homework / Exam Exam 3 –Solutions Posted –Questions? HW8 due next class Final Exam –See posted schedule Websites on UNIX systems Course Evaluations.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 24 – Web Servers (PWS, IIS, Apache, Jigsaw) Outline 24.1Introduction 24.2Microsoft Personal.
NETWORK CENTRIC COMPUTING (With included EMBEDDED SYSTEMS)
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
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.
CIS 451: Servers, CGI and Log Files Dr. Ralph D. Westfall January, 2009.
2 1 Sending Data Using a Hyperlink CGI/Perl Programming By Diane Zak.
Python CGI programming
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.
CSU - DCE Advanced Perl CGI Operation - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) on the.
HTML Hyper Text Markup Language A simple introduction.
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.
Building PERL Scripts on a Windows system* *and running those scripts on an Apache server!
CSCE Systems Programming Lecture 21 Web Server: CGI -Dynamic Pages CSCE March 25, 2013.
10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Computational Boot Camp HTML Mike Schaffer. 8/23/2002 (MES) HTML What is HTML? HTML stands for HyperText Markup Language HTML is the language for publishing.
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) Instructor: Joseph DiVerdi,
SIR and the WEB By Dave Doulton University of Southampton.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
CSE 341, S. Tanimoto Lisp CGI - 1 Lisp CGI Programming for the Web Web servers can invoke Lisp to “intelligently” create web pages on the fly. We will.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
HTML Forms. A form is simply an area that can contain form fields. Form fields are objects that allow the visitor to enter information - for example text.
Lecture 02 File and File system. Topics Describe the layout of a Linux file system Display and set paths Describe the most important files, including.
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.
CGS 3066: Web Programming and Design Spring 2016 Introduction to Server-Side Programming.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
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)
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.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
CGS 3066: Web Programming and Design Spring 2017
Distributed Control and Measurement via the Internet
CS 330 Class 7 Comments on Exam Programming plan for today:
Section 6.3 Server-side Scripting
WWW and HTTP King Fahd University of Petroleum & Minerals
Introduction to Programming the WWW I
PHP / MySQL Introduction
MapServer In its most basic form, MapServer is a CGI program that sits inactive on your Web server. When a request is sent to MapServer, it uses.
Chapter 27 WWW and HTTP.
PHP and Forms.
Lecture 5: Functions and Parameters
Intro to PHP.
Presentation transcript:

CGI Common Gateway Interface

CGI is the scheme to interface other programs to the Web Server.

CGI provides features on Web page Generating Interactive Pages –Shows current date, get server’s IP Processing Forms –Serach a database, search engines –Dynamic Pages from material in a database

How to communicate with a CGI Script? using a hyper link using FORMs

Sending info to the CGI Script A CGI Script is any program or set of commands running on the Web server that receives data from the Web page and then acts on that data to perform a certain task.

Using Link A simple CGI script Click here to see the first perl CGI script using absolute link.

firstperl.cgi #!/usr/bin/perl print "Content-type: text/html\n\n"; print " Hello World! \n";

Sending info to the CGI Script METHOD: POST vs. GET There are two methods of sending information to the CGI from the HTML form: –POST:where the user-input information is placed in the 'body' of the message (Technically, within Standard Input [STDIN]) and –GET:where the user-input information is appended to the URL that the information is sent to. With POST, the designer can design the form to accept a great deal of user- supplied information whereas with GET, because all the information is being appended to an already long URL, the amount of transferable information is limited. For most purposes, it is best to design your forms to send using a POST. If there are a very few possible fields, such as a three-word database query, GET would be suitable.

METHOD=GET A super-simple form Enter Your Name:

simpleform.cgi #!/usr/bin/perl print "content-type: text/html\n\n"; print(" "); print "The value entered was: "; print $ENV{'QUERY_STRING'}; print " "; print(" ");

METHOD=GET is the default method A super-simple form Enter Your Name:

METHOD=POST (standard input) Asuper-simple form Enter Your Name:

METHOD=POST (standard input) #!/usr/bin/perl print "content-type: text/html\n\n"; use CGI qw(:standard); $tboxcontent = param( "tbox" ); print(" "); print "The value entered was: "; print $tboxcontent; #print $ENV{'QUERY_STRING'}; print " "; print(" ");

ACTION ACTION: for most CGIs, 'where to send the info' The ACTION parameter of the HTML form declaration tells the server where to send the information, or where the server is to look for a process that can deal with the information it has received. It is in the form of a standard UNIX path. The path is usually something like “usr/bin/cgi-bin” or “var/lib/apache/cgi-bin”.

Two Roles of CGI There are two possible functions or roles that a CGI can fulfill, that of the information pipe and that of the processor itself. Facilitates Information Transfer –CGI in its most common role, acting as a facilitator, for example, a 'mail-back form processor' Acts directly Upon the Data –A CGI can act directly on the data, for example, a counter script or WAISPERL, a PERL 5 extension that is capable of creating a query without the aid of a WAIS (Wide Area Information Service) Server.

Facilitates Information TransferWeb Server Acts directly Upon the Data Two possible functions or roles that a CGI can fulfill Data

Access to a CGI SCript Because CGI Script run on the Web Server, you, as a Web page designer/author, might not have the ability to create or edit them. So, you might need the help of the system administrator.

Disadvantages of CGI Users had to be connected to the Web server to run the CGI script; only the programmer could alter the script itself; the system administrator of the Web server could place limitations on how users accessed the script, and so on. Also posed problems for the system administrator, who had to be concerned about users continually accessing the server, slowing it down, and overloading the system.

Languages of CGI Scripts CGI Scripts/Programs can be written in a variety of different computer languages: C/C++ Perl (Practical Extraction and Reporting Language) PHP (Personal Home Page tools/PHP Hypertext Processor) the UNIX shell TCL (Tool Command Language) Visual Basic

Solution Client-side programs solve many of the problems associated with CGI scripts. However, Client-side programs can never completely replace CGI Scripts. e.g., search engines.

Where CGI scripts are stored ? On most web servers, the CGI mechanism has been standardized in the following way. In the normal directory tree that the server considers to be the root you create a subdirectory named cgi-bin. The server then understands that any file requested from the special cgi-bin directory should not simply be read and sent, but instead should be executed. The output of the executed program is what it actually sent to the browser that requested the page. The executable is generally either a pure executable, like the output of a C compiler, or it is a PERL script. PERL is an extremely popular language for CGI scripting.

cgi-bin cgi-bin directory is located on linux system with default installation of Apache server: /var/lib/apache/cgi-bin cgi-bin directory is located on Windows system with Xitami server installed: C:\Xitami\cgi-bin cgi-bin directory is located on Windows system with Personal Web Server (PWS) server installed: C:\Inetpub\wwwroot\cgi-bin

cgi-bin directory for your Lab Exercise You need to create a directory called cgi-bin in the directory public_html located in your home directory: ~/public_html/cgi-bin/ All CGI scripts must have a.cgi extension and be executable.

Running a cgi script Type the following URL into your browser: The server recognized that simpleform.cgi is in the cgi-bin directory, so it executes simpleform.cgi (which is a PERL script) and sends the output from the execution to your browser.

Simple CGI Scripts Assuming that you have access to a cgi-bin directory, and assuming that you know either the C programming language or PERL, you can do a whole bunch of interesting experiments with CGI. Let's start by creating the simplest possible CGI script. The simplest possible HTML web page looks something like this: Hello there!

CGI program wrote in C++ The simplest possible CGI script would, upon execution, create this simple, static page as its output. #include int main() { cout << "Content-type: text/html\n\n"; cout \n"; cout Hello there! \n"; cout \n"; return 0; }

cout << "Content-type: text/html\n\n"; The line "Content-type: text/html\n\n" is special piece of text that must be the first thing sent to the browser by any CGI script. If you forget, the browser will reject the output of the script.

Compiling a CGI program On my web server, I have entered this program into the file simplest.cpp and then compiled it using Visual C++ compiler. On csplinux: gcc simplest.cpp -o simplest.cgi By placing simplest.cgi in the cgi-bin directory it can be executed. You can try it out now if you like by typing in or clicking on this URL: bin/simplest.cgi. As you can see, all that the script does is generate a page that says, "Hello there!".

PERL script print "Content-type: text/html\n\n"; print " Hello World! \n";

PERL script for Apache on Linux and Xitami on Windows: #!/usr/bin/perl # The above line is pointing where the Perl interpreter is. print "Content-type: text/html\n\n"; print " Hello World! \n";

Practice Go to the following site and implement all the example cgi programs on your server. How CGI Scripting Works by Marshall Brain Also write a cgi program that will take a name from a form and send you back on a dynamic Web page with server name and IP address.

Test your CGI scripts on Apache Server running on eagle telnet to eagle.auc.ca –Create a directory called public_html in your home directory (if does not exist): e.g., mkdir public_html –Change to the directory public_html : cd public_html –Create a directory called cgi-bin : mkdir cgi-bin Transfer your cgi scripts (e.g., firstperl.pl) to the cgi-bin directory using ws_ftp. Using your telnet session: –Rename your cgi scripts from.pl to.cgi e.g., mv firstperl.pl firstperl.cgi –Change file permissions to executable e.g., chmod 755 firstperl.cgi In your Browser’s address line type the following address and hit the Enter key.

CGI Environment Variables CGI- Does it stand for Can’t Get It-to-work?

SSI