More CGI Programming Multiple Submits Cookies Emailing File Uploading.

Slides:



Advertisements
Similar presentations
Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
Advertisements

Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
CGI Programming.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
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.
JavaScript Forms Form Validation Cookies CGI Programs.
Tutorial 6 Working with Web Forms
HTML Form Processing Learning Web Design – Chapter 9, pp Squirrel Book – Chapter 11, pp
CS 898N – Advanced World Wide Web Technologies Lecture 6: PERL and CGI Chin-Chih Chang
Python and Web Programming
Guide To UNIX Using Linux Third Edition
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Session Management A290/A590, Fall /25/2014.
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.
Creating Web Page Forms
File Upload Instructions and Information The File Upload utility is used for transferring files too large to send through the system. How it Works:
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
4-Sep-15 HTML Forms Mrs. Goins Web Design Class. Parts of a Web Form A Form is an area that can contain Form Control/Elements. Each piece of information.
XP Tutorial 6New Perspectives on HTML and XHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Project Four Forms Discuss form processing Describe the difference between client-side and server-side form processing Add a horizontal rule to a Web page.
Internet / Intranet Fall 2000 Class 7. Brandeis University Internet/Intranet Spring Class 7 Agenda Project / Homework Discussion Forms Validating.
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:
Let’s Make An Form! Bonney Armstrong GD 444 Westwood College February 9, 2005.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
JavaScript, Fourth Edition
Introduction to Programming the WWW I CMSC Summer 2004 Lecture 6.
USING PERL FOR CGI 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.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
Website Development with PHP and MySQL Saving Data.
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.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
1 Chapter 9 – Cookies, Sessions, FTP, and More spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
11 1 Cookies CGI/Perl Programming By Diane Zak Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Topics Sending an Multipart message Storing images Getting confirmation Session tracking using PHP Graphics Input Validators Cookies.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
Introduction to JavaScript CS101 Introduction to Computing.
Introduction to Programming the WWW I CMSC Winter 2003.
5 1 Data Files CGI/Perl Programming By Diane Zak.
WWW: an Internet application Bill Chu. © Bei-Tseng Chu Aug 2000 WWW Web and HTTP WWW web is an interconnected information servers each server maintains.
HTML Forms a form is a container for input elements on a web page input elements contain data that is sent to the web server for processing.
Forms Collecting Data CSS Class 5. Forms Create a form Add text box Add labels Add check boxes and radio buttons Build a drop-down list Group drop-down.
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.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Creating Web Page Forms COE 201- Computer Proficiency.
HTML Forms. A form is simply an area that can contain form fields. Form fields are objects that allow the visitor to enter information - for example text.
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
9/21/04 James Gallagher Server Installation and Testing: Hands-on ● Install the CGI server with the HDF and FreeForm handlers ● Link data so the server.
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
Cookies BIS1523 – Lecture 23.
What is Cookie? Cookie is small information stored in text file on user’s hard drive by web server. This information is later used by web browser to retrieve.
Presentation transcript:

More CGI Programming Multiple Submits Cookies ing File Uploading

Deciding Where to Go What if you want to have more than one functionality on your form? In other words, have more than one button the user can push. We saw last week in the dump() example that the name and value of the submit button are passed as parameters. This is useful.

Multiple Submits Just as you can have many different text fields or checkboxes, you can have different submit buttons Make sure you give each submit a different name. Only the submit button that is pressed will be passed as a parameter. Check to see if this parameter exists. if (param(‘Submit1’){ … } elsif (param(‘Submit2’){ … } else{ … }

File Uploading Another input method we did not talk about last week is a file-upload field. To use file-uploading feature, must use a special kind of form. –Add ENCTYPE=“multipart/form-data” to –Or, use start_multipart_form() instead of start_form() filefield(-name=>‘uploaded’) Creates a field in which user can enter name of file to send to server. Also creates ‘Browse’ button to search local machine. User enters name or path of a file to upload. When form submitted, CGI script can then get this file

Getting the File To get the name of the file user wants to upload, use param() function. $file = param(‘uploaded’); If you use $file as a string, it will be the name of the file. If you use $file as a filehandle, it will be a link to the actual file. print “Contents of file $file are: \n”; foreach $line { print “$line ”; }

That’s Great for Text Files… But users can upload any kind of file. Need to find out what kind of file it was. uploadInfo() function. Returns reference to a hash containing info about the file. $file = param(‘uploaded’); $info = uploadInfo($file); $type = $info->{‘Content-Type’}; $type may contain “text/html”, “text/plain”, “image/jpeg”, etc etc…

If File is not Text Need function to read from binary files. read($filename, $buffer, $size) –$filename  filehandle to read –$buffer  scalar in which to store data –$size  max number of bytes to read –returns number of bytes read $file = param(‘uploaded’); open UPLOAD, “>binary.jpg”; while ($num=read($file,$buf,1024)) { print UPLOAD $buf; } close UPLOAD;

ing from your CGI Script In actuality, you can use this process to from any Perl program. –I just feel like teaching it now. Note that this will be a Unix-specific (in fact, RPI CS dept – specific) lecture. There are ways to accomplish the same thing on Windows, but we’re not going into it.

sendmail barebones ing program. No friendly user interface whatsoever. standard with most Unix distributions. on RPI CS system, located in /usr/lib/ We need to run it with the –t flag. This tells the program to search the message for the To:, Cc:, Bcc:, etc… For more information, man sendmail

Pipes You can open a ‘pipe’ to another program or process in almost the same way you open a file. A pipe is a connection between your program and another executable program. You can feed it input as though you were writing to the file Instead of, or >>, use the | character in front of file name. open (PROG, “|myprogram.exe”) or die “Cannot open program”; For more information, CSCI-4210 & CSCI-4220

Put Them Together open (MAIL, “|/usr/lib/sendmail –t”) || die “Cannot begin mail program”; print MAIL “From: print MAIL “To: print MAIL “Subject: I want a raise!\n”; print MAIL “You know, Dr. J, I’m not quite sure this is really worth it. …\n”; close MAIL;

Cookies Love them or hate them, they exist. And you’ll learn how to use them. –learning to use them responsibly is your own task. A cookie is a (usually very small) piece of text that a server sends to a web browser for later retrieval. Can be used to ‘track’ a user’s preferences, or other information user has told the server.

To Set a Cookie Create the cookie cookie() function. Takes many (mostly optional) parameters: –-name=> Name of the cookie –-value=> Value of the cookie – can be a scalar, array reference, or hash reference –-expires=> Expiration date/time of the cookie –-path=> Path to which cookie will be returned –-domain=> Domain to which cookie will be returned –-secure=> 1 if cookie returned to SSL only

Cookie Expiration Expires: absolute or relative time for cookie to expire –+30s  in 30 seconds – +10m  in 10 minutes – +1h  in one hour –-d  yesterday (ASAP) –now  immediately –+3M  in 3 Months –+10y  in 10 Years –Wed, 05-Dec :00:00 GMT  On Wednesday, 12/5/2001 at 6pm GMT.

Cookie Path ‘region’ of server to check before sending back the cookie. If I set a cookie with path = /perl/f01/ Then only CGI scripts in /perl/f01 (and its subdirectories) will receive the cookie. By default, path is equal to the path of the current CGI script. To send cookie to all CGI scripts on server, specify path = /

Cookie Domain domain (or partial domain) to send cookie back to. must contain at least 2 periods (so can’t send cookie to all.com domains) if I set cookie domain =.rpi.edu, cookie will be sent to scripts on cgi.cs.rpi.edu, etc if set to.cs.rpi.edu, cookie only sent to cgi.cs.rpi.edu, cgi2.cs.rpi.edu, etc if set to cookie sent only to pages on Note that both domain and path must match cookie parameters to be set.

Cookie Created, Now Set it. $cookie = cookie( … ); print header(-cookie=>$cookie); To set more than one cookie, use array reference $cookie1 = cookie (…); $cookie2 = cookie (…); print header(-cookie=>[$cookie1, $cookie2]);

Read the Cookies Once again, use the cookie() function. This time, don’t use –value parameter. Just give the name $mycookie = cookie(‘lallip’); $mycookie now has value of cookie with name lallip.