CS 330 Class 10 Programming plan for today: More files Saving data from a form.

Slides:



Advertisements
Similar presentations
Socket Programming. Basics Socket is an interface between application and network – Application creates a socket – Socket type dictates the style of communication.
Advertisements

Adding Dynamic Content to your Web Site
Common Gateway Interface (CGI). CGI is a protocol: CGI is not a programming language CGI is a protocol for the exchange of information between between.
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.
Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 31/10/2007.
HTTP Cookie CSC 667/867. PERSISTENT CLIENT STATE HTTP COOKIES Cookies are a general mechanism which server side connections (such as CGI scripts) can.
CS 898N – Advanced World Wide Web Technologies Lecture 11: Internet Database Programming Chin-Chih Chang
PZ15A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ15A - The Internet Programming Language Design and.
RPC Project Using either sockets or TLI, implement Remote Procedure Calls between two distinct machines that are communicating over an Ethernet network.
Lecture 9, : The Internet, Summer : The Internet Lecture 9: Web Services II David O’Hallaron School of Computer Science and Department.
1 Web Search Interfaces. 2 Web Search Interface Web search engines of course need a web-based interface. Search page must accept a query string and submit.
Definitions, Definitions, Definitions Lead to Understanding.
Cookies & file i/o in perl. Survey (html form in notes)
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.
DBM Databases Please use speaker notes for additional information!
SE-2840 Dr. Mark L. Hornick1 Java Servlet-based web apps Servlet Architecture.
CSCI 6962: Server-side Design and Programming History and Background.
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
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.
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
HTTP HTTP stands for Hypertext Transfer Protocol. It is an TCP/IP based communication protocol which is used to deliver virtually all files and other.
Web Server Design Week 14 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 4/14/10.
ITIS 1210 Introduction to Web-Based Information Systems Chapter 23 How Web Host Servers Work.
CSU - DCE Advanced Perl CGI Operation - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) on the.
Programming in Facebook hussein suleman uct cs honours 2007.
Building PERL Scripts on a Windows system* *and running those scripts on an Apache server!
Data files using cgi/perl Please use speaker notes for additional information!
Mail with Perl/CGI Please use speaker notes for additional information!
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 9: Perl and CGI Programming CGI Programming Acknowledgement: Some materials are taken from Teach Yourself CGI Programming with PERL 5 in a Week.
Cookies Web Browser and Server use HTTP protocol to communicate and HTTP is a stateless protocol. But for a commercial website it is required to maintain.
Mainframe (Host) - Communications - User Interface - Business Logic - DBMS - Operating System - Storage (DB Files) Terminal (Display/Keyboard) Terminal.
1 Web-Based XML File Repository CS360 Project # Dongjoon Hyun.
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.
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) Instructor: Joseph DiVerdi,
1-1 HTTP request message GET /somedir/page.html HTTP/1.1 Host: User-agent: Mozilla/4.0 Connection: close Accept-language:fr request.
Murach's HTML5 and CSS3, C1© 2012, Mike Murach & Associates, Inc. Slide 1.
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.
CSE 341, S. Tanimoto Lisp CGI - 1 Lisp CGI Programming for the Web Web servers can invoke Lisp to “intelligently” create web pages on the fly. We will.
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
CS 330 Class 9 Programming plan for today: More of how data gets into a script Via environment variables Via the url From a form By editing the url directly.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Philip Repsher October 29 th, 2008 Or Maybe November 3 rd, 2008.
IF statements - selection Please use speaker notes for additional information!
Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
Web Server Design Assignment #5: Unsafe Methods & CGI Due: 05/05/2010 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin.
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.
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.
The process of establishing a connection between a client and a server is called as Client – Server communication.
Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing.
Web Server Design Week 13 Old Dominion University Department of Computer Science CS 495/595 Spring 2012 Michael L. Nelson 04/03/12.
Web Server Design Week 15 Old Dominion University Department of Computer Science CS 495/595 Spring 2009 Michael L. Nelson 4/20/09.
Sending data with CGI/Perl Please use speaker notes for additional information!
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)
1 The Internet Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
The Common Gateway Interface (CGI) Pat Morin COMP2405.
Chapter 7 - Introduction to Common Gateway Interface (CGI)
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
For Dalhousie CS4173 By J. Blustein A Flowchart-ish View
CGI II: Cookies & Stuff Web Programming.
Tiers vs. Layers.
An Example of a TCP/IP Application: the World Wide Web
CGI II: Cookies & Stuff Web Programming.
CGI II: Cookies & Stuff Web Programming.
For Dalhousie CS4173 By J. Blustein A Flowchart-ish View
Presentation transcript:

CS 330 Class 10 Programming plan for today: More files Saving data from a form

More Files Recall opening a file for reading in avggrd.pl open GRADES, "grades.dat” GRADES is the file handle (internal name), grades.dat is the file Alternate: open GRADES, ”<grades.dat” (< indicates data in) Creating a new file (file1.pl) : open FILEHANDLE, “ > filename”; write FILEHANDLE “stuff” Appending to an existing file (file2.pl): open FILEHANDLE, “ >> filename”; Reading from a file (file3.pl): open FILEHANDLE, “ < filename”;

file1.pl #!/usr/bin/perl #create a new file open AFILE, ">afile.dat" || die "Could not open afile.dat\n"; print AFILE "junk\n"; print AFILE "more junk\n"; close AFILE; file2.pl #!/usr/bin/perl # append to an existing file open AFILE, ">>afile.dat" || die "Could not open afile.dat\n"; print AFILE "junk appended\n"; print AFILE "more junk appended\n"; close AFILE;

file3.pl #!/usr/bin/perl # read an existing file open AFILE, "< afile.dat" || die "Could not open afile.dat\n"; while ( ) { print; } close AFILE; Caveat: the file must have read or write access as appropriate

Saving data A major use of CGI is to maintain data from processing a form between transactions. form4.htm - accepts form data and passes to guest4.cgi../data/guest.dat - first and last names, one name per line../data/access.dat - an integer form4.cgi –saves first and last names to guest.dat –adds one to the number in access.dat form4r.cgi –reads the names from guest.dat and sends to client access.cgi –reads the integer in access.dat and passes to client

CGI Communication Client Server HTTP server form4.cgi (5) guest.dat (1) Client requests form4.htm (2) Server sends form4.htm (3) Client returns form data with GET request to form4.cgi (4) Server executes form4.cgi (5) form4.cgi reads and writes to guest.dat and access.dat (6) Server translates form4.cgi into HTTP response to client (2) (3) (4) (1) access.dat (6)

form4.cgi = split (/&/,$ENV{'QUERY_STRING'}); foreach $pair ($field_name, $value) = split(/=/,$pair); $form{$field_name}=$value; } #add the new visitor to the file if (open GUESTFILE, ">>../data/guest.dat") { print GUESTFILE "$form{firstName}\n"; print GUESTFILE "$form{lastName}\n"; close GUESTFILE; } else{ print "Content-type: text/html\n\n"; print " \n"; print " Form Processing \n"; print " \n"; print "Guest data not saved.\n"; print " \n"; exit; }

form4.cgi (cont) #update the number of accesses to the file if (open ACCESSFILE, "</home/cs330/public_html/scripts/access.dat") { $no_accesses= ; $no_accesses++; close ACCESSFILE; open ACCESSFILE, ">/home/cs330/public_html/scripts/access.dat"; print ACCESSFILE "$no_accesses"; close ACCESSFILE; } else { open ACCESSFILE, ">../data/access.dat"; print ACCESSFILE "1"; close ACCESSFILE; } print "Content-type: text/html\n\n"; print " \n"; print " Form Processing \n"; print " \n"; print "Guest data saved.\n"; print " \n";

form4r.cgi #!/usr/bin/perl print "Content-type: text/html\n\n"; print " \n"; print " Retrieving Form Data from a File \n"; print " Visitors to this form: \n"; print " \n"; open INFILE,"<../data/guest.dat" || die "Could not open guest,dat\n"; while ( ) { $first = $_; chop($first); $last = ; chop($last); print $first," ",$last, "\n"; } print " \n";

access.cgi #!/usr/bin/perl print "Content-type: text/html\n\n"; print " \n"; print " Retrieving Data from a File \n"; print " \n"; open ACCESSFILE,"<..data//access.dat" ; $accesses = ; print "The number of visitors to this form: $accesses"; print " "; print " \n"; If time: pizza.htm