Forms, CGI Objectives. HTML forms. Form example. Form example...



Similar documents
People Data and the Web Forms and CGI. HTML forms. A user interface to CGI applications

HTML Forms and CONTROLS

HTML Form Widgets. Review: HTML Forms. Review: CGI Programs

Internet Technologies

Further web design: HTML forms

HTML Tables. IT 3203 Introduction to Web Development

Internet Technologies. World Wide Web (WWW) Proxy Server Network Address Translator (NAT)

Dynamic Content. Dynamic Web Content: HTML Forms CGI Web Servers and HTTP

Novell Identity Manager

<option> eggs </option> <option> cheese </option> </select> </p> </form>

Perl/CGI. CS 299 Web Programming and Design

10. Java Servelet. Introduction

Form Mail Tutorial. Introduction. The cgi-bin

Hello World RESTful web service tutorial

2. Follow the installation directions and install the server on ccc

Using Form Tools (admin)

Slides from INF3331 lectures - web programming in Python

CGI Programming. What is CGI?

Web Design and Development ACS Chapter 13. Using Forms 11/30/2015 1

Tutorial 6 Creating a Web Form. HTML and CSS 6 TH EDITION

Real SQL Programming 1

7 Why Use Perl for CGI?

Chapter 2: Interactive Web Applications

Intell-a-Keeper Reporting System Technical Programming Guide. Tracking your Bookings without going Nuts!

07 Forms. 1 About Forms. 2 The FORM Tag. 1.1 Form Handlers

c. Write a JavaScript statement to print out as an alert box the value of the third Radio button (whether or not selected) in the second form.

How to Make a Working Contact Form for your Website in Dreamweaver CS3

Configuring iplanet 6.0 Web Server For SSL and non-ssl Redirect

PHP Authentication Schemes

Xtreeme Search Engine Studio Help Xtreeme

PHP Form Handling. Prof. Jim Whitehead CMPS 183 Spring 2006 May 3, 2006

Designing and Implementing Forms 34

Application Security

Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture # Apache.

HTML Forms. Pat Morin COMP 2405

CTIS 256 Web Technologies II. Week # 1 Serkan GENÇ

2- Forms and JavaScript Course: Developing web- based applica<ons

IBM Tivoli Access Manager for e-business 6.1: Writing External Authentication Interface Servers

Interfacing the Apache Web Server to APLX

TCP/IP Networking, Part 2: Web-Based Control

File Manager User Guide

Protocolo HTTP. Web and HTTP. HTTP overview. HTTP overview

ICT 6012: Web Programming

DEERFIELD.COM. DNS2Go Update API. DNS2Go Update API

SOA Software API Gateway Appliance 7.1.x Administration Guide

XHTML Forms. Form syntax. Selection widgets. Submission method. Submission action. Radio buttons

Chapter 22 How to send and access other web sites

NGASI AppServer Manager SaaS/ASP Hosting Automation for Cloud Computing Administrator and User Guide

Chapter 8. Forms and Form Processing

1. Introduction. 2. Web Application. 3. Components. 4. Common Vulnerabilities. 5. Improving security in Web applications

Extending Remote Desktop for Large Installations. Distributed Package Installs

Secure Shell. The Protocol

Oracle Forms Services Secure Web.Show_Document() calls to Oracle Reports Server 6i

Computer Networks. Lecture 7: Application layer: FTP and HTTP. Marcin Bieńkowski. Institute of Computer Science University of Wrocław

Configuring IBM WebSphere Application Server 7.0 for Web Authentication with SAS 9.3 Web Applications

Web Hosting Features. Small Office Premium. Small Office. Basic Premium. Enterprise. Basic. General

APACHE WEB SERVER. Andri Mirzal, PhD N

Multimedia im Netz Online Multimedia Winter semester 2015/16. Tutorial 03 Major Subject

FORMS. Introduction. Form Basics

1 Recommended Readings. 2 Resources Required. 3 Compiling and Running on Linux

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

Perceptive Intelligent Capture Solution Configration Manager

Viewing Form Results

imhosted Web Hosting Knowledge Base

A Web Based Mumps Virtual Machine

CGI An Example. CGI Model (Pieces)

Lucid Key Server v2 Installation Documentation.

Working with forms in PHP

MIGS Payment Client Installation Guide. EGate User Manual

INTEGRATE SALESFORCE.COM SINGLE SIGN-ON WITH THIRD-PARTY SINGLE SIGN-ON USING SENTRY A GUIDE TO SUCCESSFUL USE CASE

Lesson 7 - Website Administration

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

CloudOYE CDN USER MANUAL

CloudBackup Installer Guide Linux. System Requirements. Get Started - Linux

THE PROXY SERVER 1 1 PURPOSE 3 2 USAGE EXAMPLES 4 3 STARTING THE PROXY SERVER 5 4 READING THE LOG 6

People Data and the Web Forms and CGI CGI. Facilitating interactive web applications

Secure Messaging Server Console... 2

PDG Software. Site Design Guide

JavaScript and Dreamweaver Examples

INT322. By the end of this week you will: (1)understand the interaction between a browser, web server, web script, interpreter, and database server.

SAS/IntrNet 9.4: Application Dispatcher

WEB DATABASE PUBLISHING

How to Run an Apache HTTP Server With a Protocol

Payment Response Guide. Version 4.3 September 2012 Business Gateway

Using the AVR microcontroller based web server

Contents. 2 Alfresco API Version 1.0

Fortigate SSL VPN 4 With PINsafe Installation Notes

SSH and Basic Commands

Inserting the Form Field In Dreamweaver 4, open a new or existing page. From the Insert menu choose Form.

Internet Technologies_1. Doc. Ing. František Huňka, CSc.

Phone Inventory 1.0 (1000) Installation and Administration Guide

Using IIS and UltraDev Locally page 1

Web Development 1 A4 Project Description Web Architecture

Transcription:

The basics of HTML forms How form content is submitted GET, POST Elements that you can have in forms Responding to forms Common Gateway Interface (CGI) Later: Servlets Generation of dynamic Web content Forms, CGI Objectives HTML forms In most internet programming, you need the user to enter data HTML forms offer the basic user interface elements inside HTML Forms have a method which corresponds to the HTTP command that will be sent when the form is submitted Forms have an action which denotes the URL loaded when the form is sent. The action URL is typically a CGI or a servlet Inside the form you can have normal HTML and inputs (user interface elements) gruint06/ingint06, Forms, CGI Lecture 5, slide 1 of 19 gruint06/ingint06, Forms, CGI Lecture 5, slide 2 of 19 Form example Form example... <html> <body> <form action="http://localhost/response.html" method="get"> your name: <input name="sometext" type="text" value="change me!" /><br /> your password: <input name="somepass" type="password" /><br /> <input name="thebutton" type="submit" value="click me!" /><br /> </form> </body> </html> We submit the form to the SimpleHttpServer that we wrote last time (an improved version to also accommodate POST) gruint06/ingint06, Forms, CGI Lecture 5, slide 3 of 19 gruint06/ingint06, Forms, CGI Lecture 5, slide 4 of 19

Form submission Upon submission, the form will generate the following HTTP: GET/response.html?someText=change+me%21&somePass=s ddsfs&thebutton=click+me%21 HTTP/1.1 Host: localhost Connection: Keep-Alive... and other headers The data of the form is thus sent in the HTTP command, after form s action and? The format of the data (inputname=value&...) is called a query string In the GET method the query string is limited to 65535 chars The GET query string is visible in the browser. Beware of passwords! Simply indicate the method POST POST form <html> <body> <form action="http://localhost/response.html" method="post"> your name: <input name="sometext" type="text" value="change me!" /><br /> your password: <input name="somepass" type="password" /><br /> <input name="thebutton" type="submit" value="click me!" /><br /> </form> </body> </html> gruint06/ingint06, Forms, CGI Lecture 5, slide 5 of 19 gruint06/ingint06, Forms, CGI Lecture 5, slide 6 of 19 POST form submission POST /response.html HTTP/1.1 Content-Type: application/x-www-form-urlencoded Content-Length: 59... Host: localhost sometext=change+me%21&somepass=sdfdsf&thebutton=click+me%21 When sending data with the POST method, the query string is sent after the HTTP empty line. So the query string is HTTP content By doing that, the POST method lets you send content with any length (e.g. upload large files) The POST query string is not visible in the browser! You can have both GET-style and POST query strings by <form action="somescript?p1=v1&p2=v2" method="post"> Form <input> For all HTML inputs you can indicate CSS styles, etc http://www.htmlhelp.com/reference/html40/forms/input.html type="text" and type="password" was demonstrated type="submit" creates a submit button. If you don t set any value, it will be "submit query" Most inputs have a name= (not necessarily needed for type=submit) Most inputs have a type= that determines the user interface element type Most inputs have a value= to indicate initial value type="reset" creates a button that brings all inputs to their initial value gruint06/ingint06, Forms, CGI Lecture 5, slide 7 of 19 gruint06/ingint06, Forms, CGI Lecture 5, slide 8 of 19

Dedicated input elements: Form <textarea> and <select> <textarea name="atext"> initial text multiline </textarea> http://www.htmlhelp.com/reference/html40/forms/textarea.html <select name="achoice" > <option value="1">option title</option> <option value="two">second</option> </select> http://www.htmlhelp.com/reference/html40/forms/select.html To indicate an initial value, options can be declared <option selected...> If the select is declared <select multiple...>, multiple options can be sent The query string looks like achoice=1&achoice=two etc, i.e. the name repeats for each value Checkboxes and radio buttons <input type="checkbox" name="x" value="y"/> Typically you will have more checkboxes with the same name All of the checked boxes will be sent in the query string, with the same name and the respective values, as for <select multiple > <input type="radio" name="x" value="y"/> Typically you will have more radio buttons with the same name Normally only one radio button can be checked gruint06/ingint06, Forms, CGI Lecture 5, slide 9 of 19 gruint06/ingint06, Forms, CGI Lecture 5, slide 10 of 19 Common Gateway Interface (CGI) The input/output paradigm CGI is a standard that allows us to write programs that respond to forms A standard HTTP server responds to every request For some requests (typically starting with /cgi-bin/ ) the server will start a program CGI is the interface between the HTTP server and our program CGI lets us to find out what has been in the HTTP request that the server got http://hoohoo.ncsa.uiuc.edu/cgi/overview.html http://www.cgi-resources.com Normally in DOS or Unix a program reads an input stream (so-called standard input) and writes to an output stream (so-called standard-output) A DOS or Unix program also reads its command line arguments, and its environment variables In DOS you can set an env variable like set varname=value In Unix, it depends on your shell (command line interpreter), In bash export varname=value In csh setenv varname value For example the PATH environment variable tells the system where to find programs So for input there are: standard input, command line arguments and environment variables The standard output is the only place for program output gruint06/ingint06, Forms, CGI Lecture 5, slide 11 of 19 gruint06/ingint06, Forms, CGI Lecture 5, slide 12 of 19

CGI program input/output CGI environment variables Input: a number of environment variables set by the WWW server One of the variables (the QUERY_STRING) contains arguments in the form arg1=value1&arg2=value2&... In the GET method the query string is read from the URL, after the? sign http://yourserver:port/cgi-bin/scriptname?arg1=value1&arg2=value2 In the POST method the standard input gives the query string Output: the standard output of the CGI program will be sent back to the browser! Both the HTTP headers and content Headers, empty line, content Content is typically HTML but not necessarily SERVER SOFTWARE: type of the server SERVER NAME: e.g. www,nada.kth.se SERVER PORT: e.g. 80 REQUEST METHOD: GET or POST PATH INFO: path to your program in the URL, like /cgi-bin/prog PATH TRANSLATED: path of the program on disk SCRIPT NAME: name of the CGI program QUERY STRING: actual path of the program REMOTE HOST: host where the request comes from AUTH TYPE: authentication if the user logged-in (e.g. BASIC) REMOTE USER: username if the user logged-in CONTENT TYPE: the content-type HTTP header CONTENT LENGTH: the content-length HTTP header (useful in POST) gruint06/ingint06, Forms, CGI Lecture 5, slide 13 of 19 gruint06/ingint06, Forms, CGI Lecture 5, slide 14 of 19 CGI at NADA Put your CGI program in your CGI dir at NADA (if it s activated) /afs/nada.kth.se/public/www.student/cgibin/yourusername/yourprogram Make sure that the file has execution rights chmod uo+x yourprogram cd /afs/nada.kth.se/public/www.student/cgi-bin/yourusername/ fs setacl. system:anyuser rl You should first test your program without a browser Set the CGI variables by hand using setenv (csh) or export (bash) setenv QUERY STRING a=b&c=d call yourprogram When it works, test it with a browser http://cgi.student.nada.kth.se/cgibin/yourusername/yourprogram You can check the server error log and try to find your error between other people s errors http://cgi.student.nada.kth.se/cgi-bin/get-errlog A CGI example in PERL Practical Extraction and Report Language www.perl.com http://www.iupui.edu/npi/intro2perl/perl.html http://agora.leeds.ac.uk/perl/start.html An interpreted programming language inspired by C and shellscript (bash, csh) Available on many platforms but inspired by and started on Unix Very strong pattern matching Easy to use e.g. to make a simple CGI But not for larger applications We just illustrate the CGI principle with PERL Java is not a good language to write CGI in, because CGI makes one process/http access and a Java Virtual Machine is heavy (30 Meg) Servlets are the solution in Java gruint06/ingint06, Forms, CGI Lecture 5, slide 15 of 19 gruint06/ingint06, Forms, CGI Lecture 5, slide 16 of 19

A form to respond to <FORM ACTION="/cgi-bin/test.pl" METHOD="GET"> Write a message: <INPUT TYPE="text" NAME="message" SIZE=20 MAXLENGTH=40 VALUE=""> <INPUT TYPE = "submit" VALUE= "Send it!"> <INPUT TYPE= "reset" VALUE= "Remove it!" > </FORM> Responding to a form in a PERL CGI #!/usr/local/bin/perl print "Content-type: text/html\n\n"; ## CGIs must print HTTP headers AND empty line! $REQUEST_METHOD = $ENV{ REQUEST_METHOD }; $QUERY_STRING = $ENV{ QUERY_STRING }; ## Reading environment variables if($request_method ne "GET") { print"sorry, i can only do <code>get</code><br />Bye!"; exit(0); } ($COMMAND, $MESSAGE) = split(/=/, $QUERY_STRING); ## Split the query string via PERL pattern matching. if($command eq "message") { print "<H1>You sent:</h1>"; print "Message: $MESSAGE"; exit(0); } exit(0); gruint06/ingint06, Forms, CGI Lecture 5, slide 17 of 19 gruint06/ingint06, Forms, CGI Lecture 5, slide 18 of 19 Dynamic Web content Content generated by CGI is different from normal HTTP serving It s not a static file or image that s being served Instead, a dynamic content is generated You can use CGI to generate dynamic content even if you don t respond to a form Or you can use Java servlets for the same purpose gruint06/ingint06, Forms, CGI Lecture 5, slide 19 of 19