CGI I: Basics Web Programming.

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

Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
CGI Programming.
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.
Pass data1 Passing data from an HTML page to a program Dr Jim Briggs.
CGI Programming in Perl Software Tools. Lecture 22 / Slide 2 CGI Programming l Last time we looked at designing a static web page. Today we will see how.
CGI programming in Perl Learning Objectives: 1. To understand how a CGI program works in Perl and how to make it runnable in web browsers 2. To learn how.
Dynamic content 1WUCM1. 2 Basic architecture of the web.
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.
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.
1 Homework / Exam Exam 3 –Solutions Posted –Questions? HW8 due next class Final Exam –See posted schedule Websites on UNIX systems Course Evaluations.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
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.
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
2 1 Sending Data Using a Hyperlink CGI/Perl Programming By Diane Zak.
CP476 Internet Computing CGI1 CGI is a common way to provide for specific computations on server side, interactions with users, or access to databases.
Python CGI programming
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.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: HTTP and CGI Fundamentals of Web Programming.
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 "CGI"? Common Gateway Interface A means of running an executable program via the Web. CGI is not a Perl-specific concept. Almost.
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.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
1 CGI with perl. 2 References Perl tutorials and references:
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) Instructor: Joseph DiVerdi,
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.
Netprog 2002 CGI Programming1 CGI Programming CLIENT HTTP SERVER CGI Program http request http response setenv(), dup(), fork(), exec(),...
Intermediate CGI & CGI.pm Webmaster II - Fort Collins, CO Copyright © XTR Systems, LLC CGI Programming & The CGI.pm Perl Module Instructor: Joseph DiVerdi,
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.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Week Fourteen Agenda Announcements Link of the week Review week thirteen lab assignment Next lab assignment Previous Lab Assignment Grading answers for.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
 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.
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.
Pass data1 Passing data from an HTML page to a program Dr Jim Briggs.
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
Sending data with CGI/Perl Please use speaker notes for additional information!
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.
Chapter 7 - Introduction to Common Gateway Interface (CGI)
CS 330 Class 7 Comments on Exam Programming plan for today:
CGI, FORMS and Perl CSC 3750 Fall
CS120 The Information Era TOPICS: CGI-Scripts 4/18/05
How to Write Web Forms By Mimi Opkins.
Introduction to Programming the WWW I
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.
Simple PHP application
HTML: Basic Tags & Form Tags
CGI Programming Part II UNIX Security
The HTTP Protocol COSC 2206 Internet Tools The HTTP Protocol
An Example of a TCP/IP Application: the World Wide Web
CGI I: Basics Web Programming.
CGI II: Cookies & Stuff Web Programming.
HTML: Basic Tags & Form Tags
Web Forms.
Presentation transcript:

CGI I: Basics Web Programming

CommonGatewayInterface: Intro What is CGI? mechanism that enables programs to be run via Web Why use CGI? to create dynamic, interactive Web content How does it work? a Web browser “requests” a CGI file submits a Web form <form action=hello.cgi> clicks on a CGI link <a href=hello.cgi> loads a page with <img src=counter.cgi> CGI program is executed The output of CGI program is sent back to the browser Web Programming

CGI Architecture Data CGI CGI Programs Internet User (HTTP) Web documents Web Server Web Programming

CGI Process: Form example CGI program placement CGI program is placed in designated locations with appropriate file permissions User Input User submits an HTML form from a Web browser Input to CGI program Web server passes the user input to CGI program via Environment Variables: QUERY_STRING, PATH_INFO STDIN: key=value pairs Data Processing User input is processed by a CGI program to perform certain tasks Output by CGI program CGI program outputs an HTTP document to STDOUT CGI output is sent by the Web server to the browser as an HTTP message. Web Programming

CGI Cycle: Form Example 2. Form input 1. Submits FORM CGI Program 3. CGI output 4. HTML document User Web Server Web Programming

HTML Form Syntax Example <FORM action= cgi-program method= get | post> <INPUT type=type-name name=input-name> <INPUT type=submit> </FORM> Example <form action=“cafe.cgi" method=“get”> What would you like to eat? <input type=text name=food size=15><p> What would you like to drink? <input type=text name=drink size=10><p> <input type=submit value=Order> <input type=reset value=Clear> </form> Web Programming

Form Data: Input to CGI Name=Value pair URL-encoded e.g. drink=tea URL-encoded =, &, %, +, non-printable characters are converted to hex (%xx) e.g. a&b to a%26b spaces are changed to pluses name=value pairs are delimited by & e.g. name1=value1&name2=value2 Form Data: food = “steak & lobster”, drink = “beer” URL-encoded: “food=steak+%26+lobster&drink=beer” Methods for sending input to CGI POST most common method for form sent via HTTP message body, captured via STDIN GET can send small amount of information sent via URL, captured via Environment Variable QUERY_STRING URL http://hostname/cgi-name/PATH_INFO?QUERY_STRING Web Programming

CGI Script Decode URL-encoded form data Perform program tasks using decoded input data Output HTTP document Syntax Line 1: Content-type HTTP header Line 2: blank Line 3+: HTML document Example Content-type: text/html <HTML> <HEAD></HEAD> <BODY>…</BODY> </HTML> Web Programming

CGI script: Example 1 no input, no data processing #!/usr/bin/perl print “Content-type: text/html\n\n”; print “<HTML> <HEAD><title>Hello CGI</title></HEAD> <BODY> <h1>Hello, World!</h1> </BODY> </HTML>”; Web Programming

CGI.pm Perl5 CGI module Usage syntax pre-defined functions for CGI scripts Usage syntax use CGI qw(:standard); $value = param($name); print function-name ( ); Example #!/usr/bin/perl use CGI qw(:standard); $date= param(“date”); $author= path_info(); $author= substr($author,1); print header(); print start_html(-title=>”using CGI.pm”); print h1(“Using CGI.pm”); print “This page was created using CGI.pm on $date by $author.”; print end_html(); Web Programming

CGI script: Example 2 Using CGI.pm and “here-document” quoting #!/usr/bin/perl use CGI qw(:standard); $food = param("food"); $drink = param("drink"); print "Content-type: text/html\n\n"; print <<EOP; <html> <head><title>Cyber Cafe</title></head> <body> <h3>Welcome to Cyber Cafe.</h3> You ordered <b>$food</b> and <b>$drink</b>.<br> That will be \$30. </body> </html> EOP Web Programming

Debugging CGI Run it from the command line Run it from the browser prog1.cgi name1=value1 name2=value2 e.g. cafe.cgi food=steak drink=beer use CGI qw(:standard –debug); # offline mode Run it from the browser check file permission, location, name use CGI::Carp qw(fatalsToBrowser); redirects error messages for server logs to browser Example Web Programming

CGI on WIDIT server Personal WWW root directory URL = http://widit.knu.ac.kr/~userid/ location = /home/stud/userid/public_html/ CGI files can be anywhere under the personal WWW root directory must have .cgi extension File Permissions CGI files has to be world executable HTML files has to be world readable All the parent directories of CGI and HTML files has to be world executable Recommended practice chmod 755 all your CGI files chmod 644 all your HTML files chmod 711 all your WWW directories (and your home directory) Web Programming