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

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
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
Server-Side vs. Client-Side Scripting Languages
ASP Tutorial. What is ASP? ASP (Active Server Pages) is a Microsoft technology that enables you to make dynamic and interactive web pages. –ASP usually.
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
CP476 Internet Computing Browser and Web Server 1 Web Browsers A client software program that allows you to access and view Web pages on the Internet –Examples.
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 Using Apache. Concepts Browser prepares parameter list List is attached to name of program to run on server "submit" button sends string.
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.
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.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
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)
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.
1 John Magee 9 November 2012 CS120 Lecture 17a: Publishing Web pages.
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
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.
Website Design Lecture 1. Outline Introduction to the module Outline of the Assessment Schedule Lecture Static XHTML, client side and server side Why.
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 
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.
WWW: an Internet application Bill Chu. © Bei-Tseng Chu Aug 2000 WWW Web and HTTP WWW web is an interconnected information servers each server maintains.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
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.
Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing.
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.
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.
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 (Common Gateway Interface) 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.

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 In [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.

ACTION ACTION: or, 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”, slackware 8.0: “var/www/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 can be written in a variety of different computer languages: C/C++ Perl 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. e.g., slackware 8.0 installation: “var/www/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 /var/www/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 So, for example, imagine that you type the following URL into your browser: The server recognized that search.pl is in the cgi-bin directory, so it executes search.pl (which is a PERL script) and sends the output from the execution to your browser. That is how the search engine for How Stuff Works is implemented.

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: 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";

Lab exercise 1. Go to the following site and implement all the example cgi programs on your server. How CGI Scripting Works by Marshall Brain 2. Write a cgi program(C/C++) and a script (Perl) when executed will send the following message to the browser: “This is my first cgi script.” 3. 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 csplinux telnet to csplinux.saultc.on.ca –Create a directory (if does not exist) called public_html in your home directory: 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.