Common Gateway Interface

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

DT228/3 Web Development WWW and Client server model.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
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
Tutorial 6 Working with Web Forms
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.
How Clients and Servers Work Together. Objectives Learn about the interaction of clients and servers Explore the features and functions of Web servers.
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.
Creating Web Page Forms
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Chapter 6: Hostile Code Guide to Computer Network Security.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
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.
Emlékeztető December 1.-én pótoljuk az elmaradt előadást (nov. 24-ről) az A/1 228-as teremben ig December 8.-án tartjuk a pótZH-t a sikertelen ZH-t.
17 Web Servers (Apache and IIS)
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
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)
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
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)
XP Tutorial 6New Perspectives on HTML and XHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
1 Web Server Concepts Dr. Awad Khalil Computer Science Department AUC.
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
Dr. Azeddine Chikh IS444: Modern tools for applications development.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
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.
1 HTML References: A HTML Tutorial: /HTMLPrimer.html
Copyright (c) 2010, Dr. Kuanchin Chen1 The Client-Server Architecture of the WWW Dr. Kuanchin Chen.
10 Adding Interactivity to a Web Site Section 10.1 Define scripting Summarize interactivity design guidelines Identify scripting languages Compare common.
Python CGI programming
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 21 - Web Servers (IIS, PWS and Apache) Outline 21.1 Introduction 21.2 HTTP Request Types 21.3.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
1 In the good old days... Years ago… the WWW was made up of (mostly) static documents. –Each URL corresponded to a single file stored on some hard disk.
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
Website Development with PHP and MySQL Saving Data.
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.
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.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
Overview Web Session 3 Matakuliah: Web Database Tahun: 2008.
Form Data Encoding GET – URL encoded POST – URL encoded
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.
©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.
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.
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.
National College of Science & Information Technology.
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
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.
Web Development Web Servers.
Section 17.1 Section 17.2 Add an audio file using HTML
IS333D: MULTI-TIER APPLICATION DEVELOPMENT
The HTTP Protocol COSC 2206 Internet Tools The HTTP Protocol
Environment Variables
Presentation transcript:

Common Gateway Interface CGI Common Gateway Interface

What is CGI? CGI is an acronym that stands for Common Gateway Interface is a standard for interfacing external applications with information servers, such as HTTP or Web servers This interface provides a means for browsers and the server where document resides to communicate and pass information back and forth Primarily, this is done through the <FORM> tag, but there can be other ways to use CGI effectively, like through Server Side Includes (SSI)

What is CGI? CGI, permits interactivity between a client and a host operating system through the World Wide Web via the Hyper Text Transfer Protocol (HTTP) CGI program can be written in C or C++, Perl, ASP, PHP, Python, TCL, shells, and many others languages and scripts

Examples of uses for CGI Forms forms on web sites allow the user to enter information which is processed by CGI and mailed to an administrator or logged On-the-Fly Pages web pages can be created dynamically (as needed) with up-to-date information. Database Interaction an application of on-the-fly page creation. Web pages can be created using information read from a database, or a web site form can allow a user to update database entries

Examples of uses for CGI Logging / Counters a log file can record traffic data updated with information on each visitor. A counter can be included on the web page to advertise traffic. Animation "server-push" programs can be used to feed the client successive images in an animated sequence. Catalogs, Search engines

Requirements Web server (NCSA, Apache, IIS, Microsoft Personal Web server etc.) Compiler (C/C++) or Interpreter (Perl), PHP, ASP Web browser (NN, IE etc.)

Writing CGI programs involves Obtaining input from a user or from a data file. Storing that input in program variables.  Manipulating those variables to achieve some desired purpose, and Sending the results to a file or video display.

More about FORM tag <form action=”url" method=”get" > ... Form Element tags ... </form> <form action=“http://www.ncsi.iisc.ernet.in/cgi-bin/test.pl” method =”post">  Form Elements </form> action attribute tells where the information in the form is to be sent Default method is get Examples of Forms

Form Tag Description <FORM ACTION="/cgi-bin/prog.pl" METHOD="POST">  Form Start <INPUT TYPE="text"  NAME="name" VALUE="value"  SIZE="size">                                Text Field <INPUT TYPE="password"  NAME="name" VALUE="value"  SIZE="size">                       Password Field <INPUT TYPE="hidden"  NAME="name" VALUE="value"> Hidden Field <INPUT TYPE="checkbox"  NAME="name" VALUE="value">      Checkbox <INPUT TYPE="radio"  NAME="name" VALUE="value"> Radio Button <SELECT   NAME="name" SZE=1> <OPTION SELECTED> One <OPTION>Two  …     </SELECT>  Dropdown List <INPUT TYPE="submit"   VALUE="Message!" > Submit Button <INPUT TYPE="reset"   VALUE="Message!">  Reset Button </FORM> Form Ends

Browser Request For the simple hypertext link in an HTML document: test.html Browser will send a request of the following type: GET /test.html HTTP/1.0 Accept: text/plain Accept: text/html Two blank lines

Server Response HTTP /1.0 200 OK Date: Monday, 24-Dec-2000 11:09:05 GMT Server: NCSA/1.3 MIME-version 1.0 Content-type: text/html Content-length: 231 <HTML><HEAD><TITLE>Test Page</TITLE></HEAD> <BODY> This is a simple HTML page. </BODY> </HTML>

Environment Variables (What are they used for?) In order to pass data from the server to the script, the server uses command line arguments along with environment variables. The Environment Variables are set when the server executes a CGI Script. Environment Variables allow the CGI Script to reference variables that might be wanted for the Script output. There are two types of environment variables: Non-Request specific variables - those set for every request Request specific variables - those that are dependent on the request being fulfilled by the CGI Script

Environment Variables SERVER_NAME The server's Host name or IP address SERVER_SOFTWARE The name and version of the server-software that is answering the client requests SERVER_PROTOCOL The name and revision of the information protocol the request came in with. REQUEST_METHOD The method with which the information request was issued.

Environment Variables Cont... QUERY_STRING The query information passed to the program. It is appended to the URL with a "?” CONTENT_TYPE The MIME type of the query data, such as "text/html” CONTENT_LENGTH The length of the data in bytes, passed to the CGI program through standard input. HTTP_USER_AGENT The browser the clients is using to issue the request. DOCUMENT_ROOT It displays the server document root directory

Typical Environment Variables SERVER_SOFTWARE = Apache/1.3.14 SERVER_NAME = www.ncsi.iisc.ernet.in GATEWAY_INTERFACE = CGI/1.1 SERVER_PROTOCOL = HTTP/1.0 SERVER_PORT = 80 REQUEST_METHOD = GET HTTP_ACCEPT = 'image/gif, image/x-xbitmap, image/jpeg, */*' SCRIPT_NAME = /cgi-bin/environment-example QUERY_STRING = REMOTE_HOST = ece.iisc.ernet.in REMOTE_ADDR = 144.16.64.3

Where does the data for the CGI Script come from? The most common way for data to be sent to CGI Scripts is through HTML forms. HTML forms use a multitude of input methods to get data to a CGI Script. Some of these input types are radio buttons, check boxes, text input and pull-down menus. After the input necessary for the Script is determined and what type of input are going to be used, there are two main ways to receive information using the form. The methods are Get and Post. The information will be encoded differently depending on on which method is used.

GET Method The form data is encoded and then appended to the URL after ? mark The information contained in the part of the URL after the ? mark is called the QUERY_STRING, which consists of a string of name=value pairs separated by ampersands (&) GET http://www.ncsi.iisc.ernet.in/cgi-bin/example/simple.pl?first=Jason&last=Nugent Example 3

POST Method Difference between Get and Post method is primarily defined in terms of form data encoding The information is sent after all request headers have been sent to the server With the post method, the server passes the information contained in the submitted form as standard input (STDIN) to the CGI program

POST Method ... The length of the information (in bytes) is also sent to the server, to let the CGI script know how much information it has to read The environment variable CONTENT_LENGTH contains information about how much amount of data being transferred from html form. Examples 4

Examples Counter (Counter) Database Search Example 5 Create MS Access Database Create data source (ODBC) Write scripts to access database from the browser Example 5

What are the Drawbacks of using CGI? CGI applications can be slowed down considerably if network is slow If your script is long or has to do a lot of processing, your visitor will have to wait a bit until your script is finished running Biggest concern with CGI programs is security

Server Side Include Server-side include (SSI) files add text, graphic, or application information to an HTML document just before sending the HTML file to a user Make adding dynamic content to your documents easy

SSI directives #INCLUDE #FLASTMOD #FSIZE #ECHO #CONFIG #EXEC Includes the text #FLASTMOD Retrieves the last modification time of a file. #FSIZE Retrieves the size of a file. #ECHO Inserts the value of various Common Gateway Interface (CGI)-system environment variables. #CONFIG Configures how variables and commands are displayed. #EXEC Executes CGI-system command scripts and inserts output into an HTML document.

SSI in PWS To make SSI work, the Web server must parse the HTML document and process any directives before sending the final HTML file to the client General Form <!-- #<PREPROCESSING_DIRECTIVE>--> E.g. <!-- #exec cgi=“/php/test.php”--> <!-- #echo “QUERY_STRING--> <!-- #include file=“myfile.txt” -->

SSI in Apache Add the two lines below in the main configuration file httpd.conf AddHandler server-parsed .shtml AddType text/html .shtml Restart the Apache server

Client Side Scripting Client-side programming is based on the idea that the computer which the client is using to browse the web has quite a bit of CPU power sitting there doing nothing. Meanwhile, web servers are being tasked to death handling hundreds of CGI requests above and beyond their regular duties. Thus, it makes sense to share some of that burden between the client and server by taking some of the processing load off the server and giving it to the client.

What Client side scripts can do? Scripts can be used to add interesting (Interactive Web Pages) and useful effects to Web pages (Dynamic pages) Validations and error checking Maintaining state Creating Dynamic Forms with Client-Side Scripting.

What Client side scripts can do? Cont… Instant Feedback to Users Client-Side Scripts Move Processing Tasks back to the Client

Examples Event Handling Example 6 Menu Example 7 Animation (Scrolling) Example 8

Disadvantages of Client Side Scripting Browser-Dependent Client-Side Scripts Different set of codes for both the browsers Secure Source Code of Client-Side Scripts. Pages Take Longer to Download Program Scope Is Limited to a Single HTML Page No Direct Access to System Objects

Which Should I Use? Client- or Server-Side? If you want to have dynamic client forms with client-side validation, you must use client-side scripting. If you want your site to have highly interactive pages, you should use client-side scripting. If you need to provide your client with advanced functionality that can be created only using ActiveX controls, you must use client-side scripting.

Which Should I Use? Client- or Server-Side? Cont… If you want to control the user's browser (that is, you want to turn off the menus and place the browser in kiosk mode), you must use client-side scripting If your Web site must work with every browser on the market, and you do not want to create several different versions for different browsers, you should avoid client-side scripting If you want to protect your source code, you must use only server-side scripting. All client-side source code is transferred to the browser.

Which Should I Use? Client- or Server-Side? Cont… If you need to track user information across several Web pages to create a "Web application," you must use server-side scripting If you need to interact with server-side databases, you must use server-side scripting. If you need to use HTTP server variables or check the capabilities of the user's browser, you must use server-side scripting