Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 1 Intermediate Perl Programming Class Two Instructor:

Slides:



Advertisements
Similar presentations
Social Web Design 1 Darby Chang Social Web Design.
Advertisements

Molecular Biomedical Informatics Web Programming 1.
Ruby on Rails Model of MVC. Model-View-Controller Paradigm A way of organizing a software system Benefits: Isolation of business logic from the user interface.
CGI Programming.
Lecture 14 HTML Forms CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
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.
Securing web applications using Java EE Dr Jim Briggs 1.
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.
CSE 190: Internet E-Commerce Lecture 7. HTML Templates Designed to separate server side logic from HTML presentation Key features –Escapes from HTML into.
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.
Web programming for project students Dr Jim Briggs.
CGI. 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.
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.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class One Instructor:
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 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
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:
Copyright 2000 eMation SECURITY - Controlling Data Access with
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";
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.
Building PERL Scripts on a Windows system* *and running those scripts on an Apache server!
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming.
PHP - Basic Language Constructs CSCI 297 Scripting Languages - Day Two.
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)
CGI programming Peter Verhás January What this tutorial is about Introduction to CGI programming Using ScriptBasic –Simple to program –Simple to.
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.
Chapter 9: Perl and CGI Programming CGI Programming Acknowledgement: Some materials are taken from Teach Yourself CGI Programming with PERL 5 in a Week.
Chapter 6 Server-side Programming: Java Servlets
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.
PHP Open source language for server-side scripting Works well with many databases (e.g., MySQL) Files end in.php,.php3 or.phtml Runs on all major platforms.
Topics Sending an Multipart message Storing images Getting confirmation Session tracking using PHP Graphics Input Validators Cookies.
CGI Scripting and Vulnerabilities COEN 351: E-commerce Security.
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) Instructor: Joseph DiVerdi,
Google Application Engine Introduction Jim Eng with thanks to Charles Severance
Perl Modules Darby Tien-Hao Chang Department of Electrical Engineering, National Cheng Kung University.
Intermediate CGI & CGI.pm Webmaster II - Fort Collins, CO Copyright © XTR Systems, LLC CGI Programming & The CGI.pm Perl Module Instructor: Joseph DiVerdi,
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.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
More CGI Programming Here-docs HTML::Template Cookies File Uploading Taint Checking.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class Four Instructor:
 2001 Prentice Hall, Inc. All rights reserved. Chapter 17 - Web Automation and Networking Outline 17.1Introduction 17.2Introduction to LPW 17.3 LPW Commands.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class Three Instructor:
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
Netprog CGI and Forms1 CGI and Forms A detailed look at HTML forms.
(Some from Chapter 11.9 – “Web” 4 th edition and
NMD202 Web Scripting Week2. Web site
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.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class Five Instructor:
HTML III (Forms) Robin Burke ECT 270. Outline Where we are in this class Web applications HTML Forms Break Forms lab.
Sending data with CGI/Perl Please use speaker notes for additional information!
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
Chapter 7 - Introduction to Common Gateway Interface (CGI)
CS 330 Class 7 Comments on Exam Programming plan for today:
PERL.
CGI I: Basics Web Programming.
Perl Web Page – Just Enough
CGI Programming Part II UNIX Security
Creative Commons Attribution-Share Alike License 2.0
CGI I: Basics Web Programming.
Presentation transcript:

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 1 Intermediate Perl Programming Class Two Instructor: Byrne Reese X401

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 2 Review from Last Week… Getting setup Your first program: helloworld Your first CGI: hello.cgi Homework: Web server setup

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 3 Today’s Agenda 1.Introduction to CPAN 2.Finish hello.cgi 3.Templating using Template Toolkit 4.Cookies! 5.Web Automation using LWP 6.Writing a Link Checker

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 4 CPAN

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 5 Using CPAN Comprehensive Perl Archive Network Installing Perl modules from the command line: –perl –MCPAN –e ‘shell’ –perl –MCPAN –e ‘install CGI’

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 6 Exercise Install the following modules: –CGI (‘install CGI’) –Template Toolkit (‘install Template’) –LWP (‘install LWP’) Note: accept the default configuration for all parameters, except: –Selecting your continent (5) –Selecting your country (4) –Selecting your mirrors (1,2,3,4,5)

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 7 Finishing hello.cgi

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 8 HTTP Overview HTTP Headers Cookies Query Parameters –Query Strings –POST Parameters –Files Writing Your Own CGI module

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 9 Don’t Re-invent the Wheel: Use CGI.pm

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 10 CGI.pm “use”-ing the module –use CGI qw/:standard/; –use CGI; $query = new CGI; The param() subroutine The header() subroutine –Set the content-type –Set cookies Testing via the command line

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 11 Hello World #!/usr/bin/perl use CGI qw/:standard/; print header; if (param(‘say_hello_to’)) { print “Hello “. param(‘say_hello_to’); } else { print <<END_HTML;... END_HTML }

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 12 Enhancing hello.cgi Why use templates? –Separate form and function, or “app logic and presentation layer” –Cleaner code –Easier to edit HTML –Allows non-technical and technical people to collaborate more easily Using Perl’s Template Toolkit

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 13 A Templated Hello World Example: hello.tt: [% PAGETITLE %] Enter name: <input type="text" name="say_hello_to" size="10" value=“[% SAYHELLOTO %]” />

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 14 A Templated Hello World Example: hello.cgi: use CGI; use Template; my $query = new CGI; my $tt = Template->new({ INCLUDE_PATH => "./tmpl", }); print $query->header(-type => 'text/html'); $tt->process('hello.tt', { sayhelloto => $query->param('foo'), pagetitle => 'Hello World!', } ) || die $tt->error;

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 15 Enhancing hello.cgi Using HTTP cookies –Stateful applications –Single Sign-On Exercise (if there is time)

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 16 Writing Cookies using CGI # prelude $cookie = $query->cookie( -name =>'mycookie', -value =>'xyzzy'); print $query->header(-cookie => $cookie); # yadda yadda yadda

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 17 Reading Cookies using CGI # prelude my $cookie = cookie('mycookie'); # yadda yadda yadda

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 18 Exercise Add a “Remember Me” checkbox to the Hello World form: –If the user has a cookie set that identifies them as a returning user, then do not prompt them for a name to say hello to. –The cookie should only be “session based.” Extra Credit: –Give the user a way of clearing the cookie without restarting the browser.