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.

Slides:



Advertisements
Similar presentations
Adding Dynamic Content to your Web Site
Advertisements

Tutorial 6 Creating a Web Form
Student Manager Catalog Builder An ACEware Webinar.
More CGI Programming Software Tools. Lecture 23 / Slide 2 Checkbox and Link Example l The following example shows how to generate checkboxes and links.
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.
A simple PHP application We are going to develop a simple PHP application with a Web interface. The user enters two numbers and the application returns.
More CGI Programming Learning Objectives: 1. To understand & illustrate how to produce input from different components (checkbox, textarea, links … etc)
Web Page Development Identify elements of a Web Page Start Notepad
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.
Defined/Undef my $i; if( defined $i ) #false $i=0; if( defined $i ) #true my %hash; #or %hash=(); defined %hash; #false, hash is empty $hash{“1”}=“one”;
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.
Python and Web Programming
Simple PHP application. A simple application We are going to develop a simple PHP application with a Web interface. The user enters two numbers and the.
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.
Tutorial 6: Creating a Web form
COMPUTERS AND INFORMATION SYSTEMS HTML. How the Web Works To access a web site  Enter its address (URL) in the address box of your browser 
CST JavaScript Validating Form Data with JavaScript.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
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.
1 Homework / Exam Exam 3 –Solutions Posted –Questions? HW8 due next class Final Exam –See posted schedule Websites on UNIX systems Course Evaluations.
NETWORK CENTRIC COMPUTING (With included EMBEDDED SYSTEMS)
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
ITIS 1210 Introduction to Web-Based Information Systems Chapter 24 How Websites Work with Databases How Websites Work with Databases.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
2 1 Sending Data Using a Hyperlink CGI/Perl Programming By Diane Zak.
Topic 9: The World Wide Web CSE2395/CSE3395 Perl Programming Camel3 page 878 LWP, lwpcook, CGI manpages.
CP476 Internet Computing CGI1 CGI is a common way to provide for specific computations on server side, interactions with users, or access to databases.
Perl Web Page – Just Enough Pepper. Web site Set up the top of your script to indicate perl and plain text #!/usr/bin/perl print "Content-type:text/plain\n\n";
Python CGI programming
Introduction to Programming the WWW I CMSC Summer 2004 Lecture 6.
USING PERL FOR CGI PROGRAMMING
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.
Building PERL Scripts on a Windows system* *and running those scripts on an Apache server!
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming.
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 Nine Perl and CGI Programming. 2 Objectives Basic features of Perl language Set up an HTML Web page Use Perl and CGI scripts to make your web.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
3 1 Sending Data Using an Online Form CGI/Perl Programming By Diane Zak.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
HTML Form Widgets. Review: HTML Forms HTML forms are used to create web pages that accept user input Forms allow the user to communicate information back.
Introduction to Programming the WWW I CMSC Winter 2003.
Intermediate CGI & CGI.pm Webmaster II - Fort Collins, CO Copyright © XTR Systems, LLC CGI Programming & The CGI.pm Perl Module Instructor: Joseph DiVerdi,
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
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.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
Introduction to Programming the WWW I CMSC Winter 2004 Lecture 5.
The Internet and World Wide Web Sullivan University Library.
CGI in Context CGI is Common Gateway Interface, supporting a greater degree of interaction between the user and a Web page, most commonly by means of a.
Chapter 16 Web Pages And CGI Scripts Department of Biomedical Informatics University of Pittsburgh School of Medicine
BUILDING A WEB PAGE BASIC HTML CODING. We first open notepad to start to build our web page. We enter the code at the beginning. And then we write below.
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.
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
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.
Ashima Wadhwa Java Script And Forms. Introduction Forms: –One of the most common Web page elements used with JavaScript –Typical forms you may encounter.
Chapter 7 - Introduction to Common Gateway Interface (CGI)
CGI, FORMS and Perl CSC 3750 Fall
CGI I: Basics Web Programming.
Introduction to Programming the WWW I
Perl Web Page – Just Enough
CGI Programming Part II UNIX Security
CGI I: Basics Web Programming.
Presentation transcript:

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 to retrieve & process input through web page interface 3. To learn how to generate a web page from a Perl CGI program

COMP111 Lecture 22 / Slide 2  A CGI program allows the user  to interact with a web page by generating HTML code that depends on the user input.  For example, web pages with an entry form or buttons use a CGI program to get the input from the user, and display appropriate results.  Perl is one of the most popular language for CGI programming  because it is good at text manipulation. CGI Programming (1)

COMP111 Lecture 22 / Slide 3  ihome  You can place your CGI programs in a directory called cgi-bin ihome directory ihome.ust.hk   you can place your CGI programs under your ihome web directory /cgi-bin  the URL to access your CGI program is: (or.cgi)  CS System: use the following URL pattern:   Your CGI program should have execute permission set:  chmod a+x program.cgi  (*) If you encountered “ Internal Server Error ”, you may need to transfer (FTP) your program in ASCII mode CGI Programming (2)

COMP111 Lecture 22 / Slide 4 The CGI Module  Perl has a CGI module to make it easier.  include the following line near the top of your program: use CGI qw(:standard);  The use statement is like #include in C++; it brings in predefined functions from another file at compile time.

COMP111 Lecture 22 / Slide 5 Simpler Hello World (1)  Below is the “ Hello World ” program using the CGI module: #!/usr/local/bin/perl5 -w print "Content-type:text/html\n\n"; use CGI qw(:standard); start_html("Hello World Program"); print h1("Hello world"); print start_form; print end_form; print end-html(); title

COMP111 Lecture 22 / Slide 6 Simpler Hello World (2)  In the previous program,  header() returns a string containing the Content-type line with a following blank line  start_html(string) returns string as an HTML title  h1(string) returns string as a first-level HTML heading, and  p(string) would return string as a new HTML paragraph.

COMP111 Lecture 22 / Slide 7 Adding Textfields  CGI provides various widgets for accepting user input in forms.  textfield widget: allows the user to enter text in a box  need start_form() before textfield  textfield() is often called inside a p() function.  The first argument is the name of the textfield  The second argument is the default value. print start_form; print p("Bill is: ", textfield("bill","cheap")); print end_form;

COMP111 Lecture 22 / Slide 8 Hello Gates  A form with a textfield widget: #!/usr/local/bin/perl5 -w # Bill Gates CGI program use CGI qw(:standard); $billvalue = param("bill"); # get value from bill-field print header(), start_html("Hello Bill Gates"); print h1("Hello Gates Lovers!"); if($billvalue){# display, if user has hit Return print p("Yes, Bill is $billvalue."); }else{# otherwise, ask for user-input print hr, start_form; # hr() is HTML print p("Bill is: ", textfield("bill","cheap")); print end_form, hr; } print end_html();

COMP111 Lecture 22 / Slide 9  When we click on a link that points to this program, you will see the below screen.  The text field is initially filled with the default value. Hello Gates Initial Screen

COMP111 Lecture 22 / Slide 10  In your browser, select View -> Source, you get the HTML listing: Hello Gates Initial Screen (in HTML)

COMP111 Lecture 22 / Slide 11 Bill ’ s Fans Initial Screen (1)  Here is the initial screen and default values the user sees:

COMP111 Lecture 22 / Slide 12 Bill ’ s Fans page 1 (Perl) #!/usr/local/bin/perl5 -w # Bill Gates CGI program v. 2 use strict; use CGI qw(:standard); print header(), start_html("Bill Gates Fans"); print h1("Bill Gates Fan Page"); if(param()){ # if the form has already been filled out my $who = param("name"); my $what = param("billWord"); my $howmuch = param("money"); if($howmuch == 100){ print p("Yes $who, Bill is $what, and he has 100,000,000 times more money than you!"); }else{ print p("Incorrect $who! Bill has US\$100 billion."); }  CONT…

COMP111 Lecture 22 / Slide 13 Bill ’ s Fans page 2 (Perl) }else{ # first time, so display clean form print hr(), start_form(); print p("Your name: ", textfield("name")); print p("What is Bill? ", popup_menu("billWord", ["cheap", "rich", "powerful"])); print p("How many billion US dollars does Bill have? ", popup_menu("money", [1,10,100,1000])); print p(submit("send"), reset("clear")); print end_form; } print end_html();

COMP111 Lecture 22 / Slide 14 Array references/pointers  Why the square brackets around the arrays in the previous example? ["cheap", "rich", "powerful"] [1,10,100,1000]  pointers to arrays  popup_menu() expects an array reference as its second argument.  You can also create an array reference by using a backslash in front of a named array, as in : = qw(cheap, rich, powerful); print p("What is Bill? ", popup_menu("billWord",