 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.

Slides:



Advertisements
Similar presentations
Chapter 25 Perl and CGI (Common Gateway Interface)
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Linux+ Guide to Linux Certification, Second Edition
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(26) PHP (Personal Home Page)
Guide To UNIX Using Linux Third Edition
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Introduction to scripting
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 26 - PHP Outline 26.1 Introduction 26.2 PHP 26.3 String Processing and Regular Expressions 26.4.
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
 2004 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 35 – Python Outline 35.1 Introduction First Python Program Python Keywords 35.2 Basic.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 26 - PHP Outline 26.1 Introduction 26.2 PHP 26.3 String Processing and Regular Expressions 26.4.
Chap 3: Web Programming (CCSB144) - PHP 42 Chapter 4 - PHP Outline Introduction PHP String Processing and Regular Expressions Viewing Client/Server Environment.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Introduction to Shell Script Programming
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
USING PERL FOR CGI PROGRAMMING
Web Design and Development for E-Business By Jensen J. Zhao Copyright 2003 Prentice Hall, Inc. Web Design and Development for E-Business Jensen J. Zhao.
Chapter 8 Cookies And Security JavaScript, Third Edition.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Linux+ Guide to Linux Certification, Third Edition
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
 2008 Pearson Education, Inc. All rights reserved PHP.
5 1 Data Files CGI/Perl Programming By Diane Zak.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
 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.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
REEM ALMOTIRI Information Technology Department Majmaah University.
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)
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
PHP using MySQL Database for Web Development (part II)
Chapter 7 - Introduction to Common Gateway Interface (CGI)
CS 330 Class 7 Comments on Exam Programming plan for today:
Chapter 6 JavaScript: Introduction to Scripting
Chapter 26 - PHP Outline 26.1 Introduction 26.2 PHP
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Chapter 19 PHP Part II Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Introduction to Scripting
PHP Introduction.
Intro to PHP & Variables
Chapter 7 - JavaScript: Introduction to Scripting
WEB PROGRAMMING JavaScript.
PHP.
Tutorial 6 PHP & MySQL Li Xu
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
23 PHP.
Chapter 7 - JavaScript: Introduction to Scripting
Presentation transcript:

 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing and Regular Expressions 25.4 Viewing Client/Server Environment Variables 25.5 Form Processing and Business Logic 25.6 Server-Side Includes 25.7 Verifying a Username and Password 25.8 Using DBI to Connect to a Database 25.9 Cookies and Perl Operator Precedence Chart Web Resources

 2004 Prentice Hall, Inc. All rights reserved. Objectives In this lesson, you will learn: –To understand basic Perl programming. –To understand the Common Gateway Interface. –To understand string processing and regular expressions in Perl. –To be able to read and write cookies. –To be able to construct programs that interact with MySQL databases.

 2004 Prentice Hall, Inc. All rights reserved Introduction Practical Extraction and Report Language (Perl) –One of the most widely used language for Web programming Common Gateway Interface (CGI) –Standard interface through which users interact with applications on Web servers –Provides way for clients to interact with applications on Web server –CGI script Can be written in many different languages, including Perl

 2004 Prentice Hall, Inc. All rights reserved Introduction Fig. 25.1Data path of a typical CGI-based application.

 2004 Prentice Hall, Inc. All rights reserved Perl Case sensitive Comment character ( # ) –Instruct interpreter to ignore everything on current line following # –Allows programmers to write descriptive comments in programs –“shebang” construct ( #! ) Indicates the path to the Perl interpreter print –Write text to screen Escape sequence \n –Moves output cursor to next line

 2004 Prentice Hall, Inc. All rights reserved Perl Interpolation –Replace variable with its associated data undef –In numeric context Evaluates to 0 –In a string context Empty string ( “” ) Range operator (.. ) –Specifies all values between uppercase A and uppercase Z are to replace in array

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_02.pl (1 of 1)

 2004 Prentice Hall, Inc. All rights reserved Perl

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_04.pl (1 of 2)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_04.pl (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_05.pl (1 of 2)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_05.pl (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved String Processing and Regular Expressions Text manipulation –Done with a regular expression Series of characters that serves as a pattern-matching template String-processing tasks –Can be accomplished by using Perl’s equality and comparison operators foreach statement –Iterates sequentially through elements Match operator ( m// ) –Uses regular expressions to search string for specified pattern Binding operator –Binds whatever is on its left side to a regular-expression operator on its right side

 2004 Prentice Hall, Inc. All rights reserved String Processing and Regular Expressions Metacharacters –Specify patterns or contexts that cannot be defined using literal characters Word boundary –Boundary between an alphanumeric character and something that is not an alphanumeric character + modifier –Quantifier that instructs Perl to match preceding character one or more times

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_06.pl (1 of 1)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_07.pl (1 of 2)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_07.pl (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved String Processing and Regular Expressions

 2004 Prentice Hall, Inc. All rights reserved String Processing and Regular Expressions

 2004 Prentice Hall, Inc. All rights reserved Viewing Client/Server Environment Variables Environment variables –Contain information about execution environment in which a script is being run use statement –Instructs Perl programs to include modules –Modules Contents of predefined packages –import tag :standard Import a predefined set of standard functions –Key Value name Assigned a value using the arrow operator ( => )

 2004 Prentice Hall, Inc. All rights reserved Viewing Client/Server Environment Variables %ENV hash –Built-in table in Perl that contains names and values of all environment variables Function sort –Order array of keys alphabetically

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_11.pl (1 of 2)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_11.pl (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved Form Processing and Business Logic XHTML forms –Enable Web pages collect data from users and send to Web server for processing by server-side programs and scripts –Function param Part of Perl CGI module Retrieves values from a form field’s value –Business logic (business rules) Design of verifying information –Function br Adds a break ( ) to XHTML page –Functions span and div Adds and to page respectively

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_12.html (1 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_12.html (2 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_12.html (3 of 3)

 2004 Prentice Hall, Inc. All rights reserved.

Outline fig25_13.pl (1 of 4)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_13.pl (2 of 4)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_13.pl (3 of 4)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_13.pl (4 of 4)

 2004 Prentice Hall, Inc. All rights reserved Server-Side Includes Commands embedded in XHTML documents to allow creation of simple dynamic content Written as XHTML comments.shtml file extension ( s stands for server) –Parsed by server ECHO command –Display variable information Keyword VAR –Specifies name of the variable EXEC –Can be used to run CGI scripts and embed their output directly into Web page

 2004 Prentice Hall, Inc. All rights reserved Server-Side Includes Diamond operator <> –Read one line of file referred to by filehandle COUNTREAD > character –Write mode Append mode ( >> ) –Appending to the end of a file Function close –Terminates connection for structure –Iterates Function length –Returns length of character string

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_14.shtml (1 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_14.shtml (2 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_14.shtml (3 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_15.pl (1 of 1)

 2004 Prentice Hall, Inc. All rights reserved.

25.7 Verifying a Username and Password Private Web sites –Visible only to certain people –Username and password verification chomp –Remove newline character at end of line split –Divide string into substrings at specified separator

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_16.html (1 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_16.html (2 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_16.html (3 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_17.pl (1 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_17.pl (2 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_17.pl (3 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline password.txt (1 of 1)

 2004 Prentice Hall, Inc. All rights reserved.

25.8 Using DBI to Connect to a Database Perl DBI (Database Interface) prepare execute disconnect finish

 2004 Prentice Hall, Inc. All rights reserved Using DBI to Connect to a Database Perl DBI (Database Interface), cont. –Access different types of databases uniformly –Perl Package Manager (PPM) Download and install Perl modules and packages Start PPM –Type ppm at command prompt –Interactive mode Database handles –Create and manipulate connection to database Statement handles –Create and manipulate SQL statements to database DBI method connect –Connect to database

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_19.pl (1 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_19.pl (2 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_19.pl (3 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_20.pl (1 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_20.pl (2 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_20.pl (3 of 3)

 2004 Prentice Hall, Inc. All rights reserved.

25.9 Cookies and Perl Cookies –Maintain state information –Function time Returns current date and time –SetCookie: header Indicate browser should store incoming data in cookie –HTTP_COOKIE Contains client’s cookies

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_21.html (1 of 2)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_21.html (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_22.pl (1 of 2)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_22.pl (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved Cookies and Perl Fig Cookies directory before a cookie is written.

 2004 Prentice Hall, Inc. All rights reserved Cookies and Perl Fig Cookies directory after a cookie is written.

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_25.pl (1 of 2)

 2004 Prentice Hall, Inc. All rights reserved. Outline fig25_25.pl (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved.

25.10 Operator Precedence Chart

 2004 Prentice Hall, Inc. All rights reserved Operator Precedence Chart

 2004 Prentice Hall, Inc. All rights reserved Operator Precedence Chart

 2004 Prentice Hall, Inc. All rights reserved Operator Precedence Chart