COS 381 Day 20. Agenda  Assignment #5 Due  Capstone Progress Reports Overdue Were Due April 7  Capstone projects are DUE May 10 at 1PM  Assignment.

Slides:



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

Web forms and CGI scripts Dr. Andrew C.R. Martin
HTML Forms. collect information for passing to server- side processes built up from standard widgets –text-input, radio buttons, check boxes, option lists,
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?
Lecture 11 Server Side Interaction
HyperText Markup Language (HTML). Introduction to HTML Hyper Text Markup Language HTML Example The structure of an HTML document Agenda.
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.
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
Using Perl for CGI Programming
B.Sc. Multimedia ComputingMedia Technologies Database Technologies.
COS 381 Day 22. Agenda  Assignment #5 Corrected 2 B’s, 1 C, and 3 D’s  Next Capstone progress report due April 21  Capstone projects are DUE May 10.
COS 381 Day 23. Agenda  Questions??  Resources Source Code Available for examples in Text Book in Blackboard
Cookies & file i/o in perl. Survey (html form in notes)
Guide To UNIX Using Linux Third Edition
COS 381 Day 23. Agenda  Questions??  Resources Source Code Available for examples in Text Book in Blackboard
1 The World Wide Web. 2  Web Fundamentals  Pages are defined by the Hypertext Markup Language (HTML) and contain text, graphics, audio, video and software.
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.
Chapter 2 Introduction to HTML5 Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
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.
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.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
JAVASCRIPT HOW TO PROGRAM -2 DR. JOHN P. ABRAHAM UTPA.
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.
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
Chapter 16 The World Wide Web Chapter Goals ( ) Compare and contrast the Internet and the World Wide Web Describe general Web processing.
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
Chapter 16 The World Wide Web Chapter Goals Compare and contrast the Internet and the World Wide Web Describe general Web processing Describe several.
Server-side Scripting Powering the webs favourite services.
Chapter 16 The World Wide Web. 2 The Web An infrastructure of information combined and the network software used to access it Web page A document that.
CP476 Internet Computing Lecture 5 : HTTP, WWW and URL 1 Lecture 5. WWW, HTTP and URL Objective: to review the concepts of WWW to understand how HTTP works.
JavaScript, Fourth Edition
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.
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.
Chapter 8 Cookies And Security JavaScript, Third Edition.
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.
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 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.
1 © Copyright 2000 Ethel Schuster The Web… in 15 minutes Ethel Schuster
Chapter 10 © 2003 by Addison Wesley Longman, Inc. 1 Chapter 10 Using Perl for CGI Programming.
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,
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.
Saving State on the WWW. The Issue  Connections on the WWW are stateless  Every time a link is followed is like the first time to the server — it has.
CP476 Internet Computing CGI1 Cookie –Cookie is a mechanism for a web server recall info of accessing of a client browser –A cookie is an object sent by.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
 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.
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.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Chapter 5 © 2002 by Addison Wesley Longman, Inc. 1 Chapter 5 Sebesta: Programming the World Wide Web.
Chapter 7 - Introduction to Common Gateway Interface (CGI)
Chapter 27 WWW and HTTP.
10.1 The Common Gateway Interface
Presentation transcript:

COS 381 Day 20

Agenda  Assignment #5 Due  Capstone Progress Reports Overdue Were Due April 7  Capstone projects are DUE May 10 at 1PM  Assignment #6 Posted Due Tuesday, April 18 at 3:35PM  Exam 3 which was originally scheduled for Apr 4 is going to on April 18 XML & Perl (Chap 8-10) 25 M/C WebCT  Lecture/discuss CGI using Perl

Overview  How CGI works Some simple examples  How CGI is setup on perleybrook  Query String Format  Using the CGI.pm module An example of an order form  Using text files with Perl CGI A survey example  Creating and using Cookies  Old School animation techniques using CGI

- Markup languages cannot be used to specify computations, interactions with users, or to provide access to databases - CGI is a common way to provide for these needs, by allowing browsers to request the execution of server-resident software - CGI is just an interface between browsers and servers - An HTTP request to run a CGI program specifies a program, rather than a document - Servers can recognize such requests in two ways: 1. By the location of the requested file (special subdirectories for such files) This method is used by Apache Web Server 2. A server can be configured to recognize executable files by their file name extensions. This method is used by Microsoft IIS - A CGI program can produce a complete HTTP response, or just the URL of an existing document 10.1 The Common Gateway Interface

- CGI programs often are stored in a directory named cgi-bin or scripts - Some CGI programs are in machine code, but Perl programs are usually kept in source form, so perl must be run on them - A source file can be made to be “executable” by adding a line at their beginning that specifies that a language processing program be run on them first For Perl programs, if the perl system is stored in /usr/local/bin/perl, as is often is in UNIX systems, this is #!/usr/local/bin/perl -w - An HTML document specifies a CGI program with the hypertext reference attribute, href, of an anchor tag,, as in <a href = " Click here to run the CGI program, reply.pl 10.2 CGI Linkage

HTML to call the CGI-Perl program reply.pl This is our first CGI-Perl example <a href = " Click here to run the CGI program, reply.pl - The connection from a CGI program back to the requesting browser is through standard output, usually through the server - The HTTP header needs only the content type, followed by a blank line, as is created with: print "Content-type: text/html \n\n"; 10.2 CGI Linkage (continued)

#!/usr/local/bin/perl # reply.pl – a CGI program that returns a # greeting to the user print "Content-type: text/html \n\n", " \n", " reply.pl example ", " \n", " \n", " Greetings from your Web server!", " \n \n"; CGI Linkage (continued)

Class GGI setup  I have placed a CGI directory in each of your web accounts and enabled this directory to run CGI perl scripts and do file creation  Referring to this directory For perl scripts  <a href= classes/cos381/instructor/cgi/*.pl> For file manipulation within Perl scripts  open(INDAT, "<cos381/instructor/cgi/indat.dat“)  I have placed in each of your CGI directories the sample CGI programs used in this lecture Some scripts have to modified for your directory  Change “instructor” to your last name  open(INDAT, "<cos381/instructor/cgi/indat.dat“)  open(INDAT, "<cos381/page/cgi/indat.dat“)

- A query string includes names and values of widgets - Widget values are always coded as strings- The form of a name/value pair in a query string is: name = value - If the form has more than one widget, their values are separated with ampersands milk=2&payment=visa - Each special character is coded as a percent sign and a two- character hexadecimal number (the ASCII code for the character) - Some browsers code spaces a plus signs, rather than as %20 We will use Perl CGI scripts to process these query strings 10.3 Query String Format

- A Perl module serves as a library - The Perl use declaration is used to make a module available to a program - To make only part of a module available, specify the part name after a colon (For our purposes, only the standard part of the CGI module is needed) use CGI " :standard " ; - Common CGI.pm Functions - “Shortcut” functions produce tags, using their parameters as attribute values - e.g., h2("Very easy!"); produces Very easy! - In this example, the parameter to the function h2 is used as the content of the tag 10.4 The CGI.pm Module

- Tags can have both content and attributes - Each attribute is passed as a name/value pair, just as in a hash literal - Attribute names are passed with a preceding dash textarea(-name => "Description", -rows => "2", -cols => "35" ); Produces: <textarea name ="Description" rows=2 cols=35> 10.4 The CGI.pm Module (continued)

- If both content and attributes are passed to a function, the attributes are specified in a hash literal as the first parameter a({-href => "fruit.html"}, "Press here for fruit descriptions"); Output: Press here for fruit descriptions - Tags and their attributes are distributed over the parameters of the function ol(li({-type => "square"},["milk", "bread", "cheese"])); Output: - CGI.pm also includes non-shortcut functions, which produce output for return to the user - A call to header() produces: Content-type: text/html;charset=ISO blank line The CGI.pm Module (continued)

- The start_html function is used to create the head of the return document, as well as the tag - The parameter to start_html is used as the title of the document start_html("Bill’s Bags"); DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " DTD/xhtml11-transitional.dtd " > Bill’s Bags - The param function is given a widget’s name; it returns the widget’s value - If the query string has name=Abraham in it, param("name") will return "Abraham" - The end_html function generates  SHOW popcorn.html, its display, and popcorn.pl popcorn.htmlpopcorn.pl 10.4 The CGI.pm Module (continued)

- We will use a form to collect survey data from users - The program needs to accumulate survey results which must be stored between form submissions - Store the current results in a file on the server - Because of concurrent use of the file, it must be protected from corruption by blocking other accesses while it is being updated - This can be done with the Perl function, flock, using the parameter value 2 to specify a lock operation and 8 to specify an unlock operation --> SHOW conelec.html and its display conelec.html - Two CGI programs are used for this application, one to collect survey submissions and record the new data, and one to produce the current totals - The file format is eight lines, each having seven values, the first four lines for female responses and the last four lines for male responses 10.5 A Survey Example

File Format

- The program to collect and record form data must: 1. Decode the data in the query string 2. Determine which row of the file must be modified 3. Open, lock, read, unlock, and close the survey data file 4. Split the affected data string into numbers and store them in an array 5. Modify the affected array element and join the array back into a string 6. Open, lock, write, unlock, and close the survey data file --> SHOW conelec1.pl conelec1.pl 10.5 A Survey Example (continued)

Agenda  Assignment #6 Posted Due Tuesday, Nov 25 at midnight UMFK policy will be applied  Quiz #3 Chap 8, 9 & 10,25 M/C WebCT, 50 min Exam can be taken from AM EST Monday, November 24, 2003 Password will be ed to you via WebCT You do not have to be in N105 in take exam  Discuss using Perl for CGI programming

- Tables are easier to specify with CGI.pm - The table is created with the table function - The border attribute is specified as a parameter - The table’s caption is created with a call to caption, as the second parameter to table - Each row of the table is created with a call to Tr - A heading row is created with a call to th - Data cells are created with calls to td - The calls to Tr, th, and td require references as parameters - Suppose we have three arrays of sales numbers, one for each of three salespersons; each array has one value for each day of the work week - We want to build a table of this information, using CGI.pm 10.5 A Survey Example (continued)

table({-border => "border"}, caption("Sales Figures"), Tr( [th(["Salesperson", "Mon", "Tues", "Wed", "Thu", "Fri"]), ] ) ); 10.5 A Survey Example (continued)

- The program that produces current results must: 1. Open, lock, read the lines into an array of strings, unlock, and close the data file 2. Split the first four rows (responses from females) into arrays of votes for the four age groups 3. Unshift row titles into the vote rows (making them the first elements) 4. Create the column titles row with th and put its address in an array 5. Use td on each rows of votes 6. Push the addresses of the rows of votes onto the row address array 7. Create the table using Tr on the array of row addresses 8. Repeat Steps 2-7 for the last four rows of data (responses from males) --> SHOW conelec2.plconelec2.pl 10.5 A Survey Example (continued)

- A session is the collection of all of the requests made by a particular browser from the time the browser is started until the user exits the browser - The HTTP protocol is stateless - But, there are several reasons why it is useful for the server to relate a request to a session - Shopping carts for many different simultaneous customers - Customer profiling for advertising - Customized interfaces for specific clients - Approaches to storing client information: - Store it on the server – too much to store! - Store it on the client machine - this works 10.6 Cookies

- A cookie is an object sent by the server to the client - Cookies are created by some software system on the server (maybe a CGI program) - Every HTTP communication between the browser and the server includes information in its header about the message - At the time a cookie is created, it is given a lifetime - Every time the browser sends a request to the server that created the cookie, while the cookie is still alive, the cookie is included - A browser can be set to reject all cookies - CGI.pm includes support for cookies cookie(-name => a_cookie_name, -value => a_value, -expires => a_time_value); - The name can be any string - The value can be any scalar value - The time is a number followed by a unit code ( d, s, m, h, M, y ) 10.6 Cookies (continued)

- Cookies must be placed in the HTTP header at the time the header is created header(-cookie => $my_cookie); - To fetch the cookies from an HTTP request, call cookie with no parameters - A hash of all current cookies is returned - To fetch the value of one particular cookie, send the cookie’s name to the cookie function $age = cookie( ′ age ′ ); - Example: A cookie that tells the client the time of his or her last visit to this site - Use the Perl function, localtime, to get the parts of time ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime;  SHOW day_cookie.pl day_cookie.pl  SHOW cookie_raider.plcookie_raider.pl 10.6 Cookies (continued)

- CGI was once a good way to create animation, but now there are several better ways - There are two ways to use CGI to create animation neither of which requires user intervention 1. Client-pull animation - The client repeatedly requests images from the server, which it displays in sequence - Problems: Internet is not fast enough, and if the approach were widely used, it would pull down the speed of the whole Internet 2. Server-push animation - The server sends the sequence of images to the client, with delays between them - Problems: Also creates a huge load on the Internet, and it is supported only by Netscape 10.7 Animation Using CGI