M.P. Johnson, DBMS, Stern/NYU, Sp20041 C20.0046: Database Management Systems Lecture #20 Matthew P. Johnson Stern School of Business, NYU Spring, 2004.

Slides:



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

Molecular Biomedical Informatics Web Programming 1.
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
W EB A PPLICATION D EVELOPMENT A PPLICATION T O B IO -I NFORMATICS -III Vicky Khanna M-Tech Bioinformatics.
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #20 M.P. Johnson Stern School of Business, NYU Spring, 2005.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #22 M.P. Johnson Stern School of Business, NYU Spring, 2005.
M.P. Johnson, DBMS, Stern/NYU, Sp20041 C : Database Management Systems Lecture #21 Matthew P. Johnson Stern School of Business, NYU Spring, 2004.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #21 M.P. Johnson Stern School of Business, NYU Spring, 2005.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #16 M.P. Johnson Stern School of Business, NYU Spring, 2008.
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.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.
 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.
PHP: Introduction By Trevor Adams.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
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.
1 Homework / Exam Exam 3 –Solutions Posted –Questions? HW8 due next class Final Exam –See posted schedule Websites on UNIX systems Course Evaluations.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
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.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
INTERNET APPLICATION DEVELOPMENT For More visit:
Introduction to Perl Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister or …
Introduction to Programming the WWW I CMSC Summer 2004 Lecture 6.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
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.
CGI Security COEN 351. CGI Security Security holes are exploited by user input. We need to check user input against Buffer overflows etc. that cause a.
Website Design Lecture 1. Outline Introduction to the module Outline of the Assessment Schedule Lecture Static XHTML, client side and server side Why.
10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0.
Website Development with PHP and MySQL Saving Data.
CGI Programming. What is it? CGI –Common Gateway Interface Standard way to pass information back to the Web Server –GET Query String –POST Standard Input.
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.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
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.
CS 4720 Dynamic Web Applications CS 4720 – Web & Mobile Systems.
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.
3 1 Sending Data Using an Online Form CGI/Perl Programming By Diane Zak.
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) Instructor: Joseph DiVerdi,
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
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,
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
 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 th Semester, Batch 2009 Department Of Computer Science SSUET.
How CGI and Java Servlets are Run By David Stein 14 November 2006.
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.
JavaScript: A short introduction Joseph Lee Created by Joseph Lee.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
1 CGI (Common Gateway Interface) CmpE 587 Emir Bayraktar Onur Bük.
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.
CS 330 Class 7 Comments on Exam Programming plan for today:
CGI I: Basics Web Programming.
PHP / MySQL Introduction
CGI I: Basics Web Programming.
Presentation transcript:

M.P. Johnson, DBMS, Stern/NYU, Sp20041 C : Database Management Systems Lecture #20 Matthew P. Johnson Stern School of Business, NYU Spring, 2004

M.P. Johnson, DBMS, Stern/NYU, Sp Agenda Previously: PL/SQL Next: Project part 3 really due now  Bad date Project part 4 due next week  Tuesday Scripting for SQL on the web  CGI/Perl  PHP Security

M.P. Johnson, DBMS, Stern/NYU, Sp New topic: web apps Goal: web front-end to database  Present dynamic content, on demand  Not canned (static) pages/not canned queries  (perhaps) modify DB on demand Naïve soln: static webpage & HTTP  index.html written, stored, put on server, displayed when it’s url is requested  HTTP is stateless (so?)  This doesn’t solve our problem

M.P. Johnson, DBMS, Stern/NYU, Sp Dynamic webpages Soln 1: upon url request 1. somehow decide to dynamically generate an html page (from scratch) 2. send back new html page to user  No html file exists on server, just created on demand  CGI, Java servlets, etc.

M.P. Johnson, DBMS, Stern/NYU, Sp New topic: CGI First, and still very popular, mechanism for first soln CGI: Common Gateway Interface  Not a programming language!  Just an interface (connection) between the webserver and a program  Very simple basic idea: user chooses an url  webserver runs that url’s program, sends back the program’s output

M.P. Johnson, DBMS, Stern/NYU, Sp On-the-fly content with CGI Image from Program Client Server HTTP Request Data for program Generated HTML HTML

M.P. Johnson, DBMS, Stern/NYU, Sp Using CGI CGI works with any prog./scripting lang. Really? Well, any language your server works with  I.e., the machine running your webserver program pages/soho, not sales  And that the user the webserver is running as (e.g. nobody) can use and has env. vars. for  And whose jars/libaries are available and whose permissions are set  And (for us) whose MySQL dependencies are installed Plausible choices: Perl, Python, C

M.P. Johnson, DBMS, Stern/NYU, Sp CGI admin Most webservers: CGI program/script must either 1. End in.cgi or 2. Reside in cgi-bin Ours: needs.cgi extention If a program, the cgi file is just the name of the executable: gcc -o myprog.cgi myproc.gcc

M.P. Johnson, DBMS, Stern/NYU, Sp CGI admin If a script, first (“shebang”) line says which interpreter to use: Either way, cgi file must be executable: Make sure your cgi file runs at cmd prompt:  But not a guarantee! #!/usr/local/bin/perl sales% chmod +x *.cgi sales% myprog.cgi

M.P. Johnson, DBMS, Stern/NYU, Sp CGI input CGI programs must respond to input Two mechanisms:  GET: read env. var. QUERY_STRING  POST: get length from env. var. CONTENT_LENGTH; read from STDIN This diff. mostly invis. to Perl, PHP Both send a sequence of name/value pairs, separated by &s: name=a&submit=Search

M.P. Johnson, DBMS, Stern/NYU, Sp CGI input Appearance/security differences GET: string is part of the URL, following a ?: POST: string can be read by program from an environmental variable  Vars not visible to the browser user  Not automatically put in server log, etc. perl/lookup.cgi?name=1&submit=Search

M.P. Johnson, DBMS, Stern/NYU, Sp Our use of CGI We’ll discuss CGI and Perl  One option for your project  Can try C, C++, etc.  But not recommended! For CGI, only Perl will be supported  Scripting languages v. programming languages  Development v. IT  Other languages are still not recommended especially if you don’t know Perl and PHP

M.P. Johnson, DBMS, Stern/NYU, Sp New topic: Just Enough Perl Very popular, powerful scripting language Very good at “regular expressions”, text manipulation, but not very relevant to us Instead:  simple text/html production  Basic language constructs  MySQL connectivity Perl = Practical Extraction and Report Language or = Pathologically Eclectic Rubbish Lister perl -pi -e 's/tcsh/sh/' $HOME/.login See

M.P. Johnson, DBMS, Stern/NYU, Sp hello.pl Hello, World - hello.pl Running at command prompt: #! /usr/bin/perl -w print "Hello World\n"; #! /usr/bin/perl -w print "Hello World\n"; sales% perl hello.pl Hello World sales% sales% perl hello.pl Hello World sales%

M.P. Johnson, DBMS, Stern/NYU, Sp Hello, World - hello.pl Run from browser:  What’s wrong?  What’s wrong?  What’s wrong?

M.P. Johnson, DBMS, Stern/NYU, Sp Hello, World – hello3.cgi Script errors, w/ and w/o fatalsToBrowser:  #! /usr/bin/perl -w use CGI qw(:standard); use CGI::Carp qw( fatalsToBrowser warningsToBrowser ); print header(); pr int "Hello World\n"; #! /usr/bin/perl -w use CGI qw(:standard); use CGI::Carp qw( fatalsToBrowser warningsToBrowser ); print header(); pr int "Hello World\n";

M.P. Johnson, DBMS, Stern/NYU, Sp More on Perl Perl is mostly “C-like” Perl is case-sensitive Use # for rest-of-line comments Creation of functions are supported but optional Perl has “modules”/“packages” CGI module:  Provides header() function, access to params Mysql module: use CGI qw(:standard); use Mysql;

M.P. Johnson, DBMS, Stern/NYU, Sp Perl and strings Can use “ ” for strings Concatenate with. op: Print text with print function: Or, parentheses can be dropped! “Hi ”. “there\n” print (“Hi there”); print “Hi there”;

M.P. Johnson, DBMS, Stern/NYU, Sp Perl and strings Can compare numbers (as numbers) with usual operators  <=, etc.  3 < 5 These do not apply to strings String ops are based on initials of operations:  eq, ne, lt, gt, le, ge  “hi” ne “there”  “hi” le “hi there”

M.P. Johnson, DBMS, Stern/NYU, Sp Perl and variables Regular variables begin with $  $input, $query Declare vars with my: Q: What about var types? A: Perl is loosely typed! my $s = “hi”; my $query = “select …”; my $s = “hi”; my $query = “select …”; my $s = “hi”; $s = 10; $s = 3.5; my $s = “hi”; $s = 10; $s = 3.5;

M.P. Johnson, DBMS, Stern/NYU, Sp Perl, strings, and variables print takes var-many arguments: Variables are always “escaped” Vars may appear within strings: Prints out: Hello Dolly.  To prevent, use single quotes ‘ ‘ $name = “Dolly”; print (“Hello $name.\n”); print (“Hello ”, “Dolly”. “.\n”);

M.P. Johnson, DBMS, Stern/NYU, Sp Perl syntax examples Access member/field of object ::  object::member Access member pointed to by object ->  rowhash->field Can access array members with indices Can access hash members with strings perl/controlscgi.txt perl/controlscgi.txt

M.P. Johnson, DBMS, Stern/NYU, Sp Tutorials on Perl Some material drawn from the following good tutorials: CGI backend programming using perl:  Perl Basics:  CGI Basics:  MySQL/Perl/CGI example: 

M.P. Johnson, DBMS, Stern/NYU, Sp Tutorials on PHP Some material drawn from the following good tutorials: PHP introduction and examples:  Interactive PHP with database access:  Longer PHP/MySQL Tutorial from webmonkey:  Nice insert/update/delete example from webmonkey:  MySQL/Perl/PHP page from U-Wash: 

M.P. Johnson, DBMS, Stern/NYU, Sp Comparison of scripting languages PHP v. Perl:  PHP v. Perl v. Java servlets v. …:  -side-scripting-language/ -side-scripting-language/