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.

Slides:



Advertisements
Similar presentations
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Advertisements

The Web Warrior Guide to Web Design Technologies
CIS101 Introduction to Computing Week 08. Agenda Your questions JavaScript text Resume project HTML Project Six This week online Next class.
Chapter 31 Basic Form-Processing Techniques JavaServer Pages By Xue Bai.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
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.
HTML Form Processing Learning Web Design – Chapter 9, pp Squirrel Book – Chapter 11, pp
Python and Web Programming
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.
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
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.
UFCEKG-20-2 Data, Schemas & Applications Lecture 4 Server Side Scripting & PHP.
Client-Side programming with JavaScript 3
MIT AITI 2004 JSP – Lecture 2 Get and Post Requests.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
Chapter 4 Handling User Input PHP Programming with MySQL 2nd Edition
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Form Handling.
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.
PHP Forms and User Input The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.
INTERNET APPLICATION DEVELOPMENT For More visit:
Lecture 7 – Form processing (Part 2) SFDV3011 – Advanced Web Development 1.
Web Application Architecture and Communication. Displaying a Web page in a Browser
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Server-side Scripting Powering the webs favourite services.
CGI programming Using Apache. Concepts Browser prepares parameter list List is attached to name of program to run on server "submit" button sends string.
Lecture 7 Interaction. Topics Implementing data flows An internet solution Transactions in MySQL 4-tier systems – business rule/presentation separation.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
USING PERL FOR CGI PROGRAMMING
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
Website Development with PHP and MySQL Saving Data.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
JavaScript - A Web Script Language Fred Durao
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
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.
HTML Form Widgets. Review: HTML Forms HTML forms are used to create web pages that accept user input Forms allow the user to communicate information back.
Introduction to JavaScript CS101 Introduction to Computing.
Introduction to Programming the WWW I CMSC Winter 2003.
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
 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.
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 Form Processing * referenced from
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
CIS 228 The Internet 12/6/11 Forms and Validation.
INTERNET APPLICATIONS CPIT405 Forms, Internal links, meta tags, search engine friendly websites.
Web Services Essentials. What is a web service? web service: software functionality that can be invoked through the internet using common protocols like.
HTML III (Forms) Robin Burke ECT 270. Outline Where we are in this class Web applications HTML Forms Break Forms lab.
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.
Simple PHP Web Applications Server Environment
How to Write Web Forms By Mimi Opkins.
Section 17.1 Section 17.2 Add an audio file using HTML
Simple PHP application
Presentation transcript:

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 application returns the two multiplied to together Start

UML Interaction Diagram Interaction diagrams describe the communication between objects, but we will use them to describe interation between programs even if they are not objects

Simple interaction diagram Simple example and explanation Ref to UML

User-script interaction Browser Web server get multiply.php?x=5&y=6 Locate file and run as PHP multiply.php PHP processor run script “5 * 6 = 30” 5 * 6 = 30 HTML MIME User Enter data Read output get form.htm Click link Locate file Calculate button x=5 y=6 Display form.htm Display generated HTML page

User-browser interaction Browser User Enter data Read output Click link Calculate button Display form.htm Display generated HTML page

User – Browser interaction User locates desired link Multiply numbers Browser retrieves the form from the server Form is displayed User fills in the fields on the form User clicks submit button Magic stuff happens User reads the result and goes back to the form to change the values in the form

form.htm <!-- this is not XHTML standard because it lacks headers but it does have all attribute values in quotes and all tags are terminated --> x = y =

Browser-Server interaction Browser Web server get multiply.php?x=5&y=6 Locate file and run as PHP 5 * 6 = 30 Click button

Browser-Server interaction Parameters passed as data couplets (name/value pairs) either –Attached to URL (and visible to user in the address line) Values must be URL-Encoded –space to + –punctuation to %hex e.g. ? to %3f METHOD=GET in an HTML Form –appended to the ACTION URL Explicitly added to the base URL e.g. – 5 * 6 multiply.php?x=5&y=6 –A separate document (invisible to user) METHOD=POST in an HTML Form Result passed back in a MIME wrapper –MIME tells browser what kind of file it is (HTML,JPEG, XML, Flash.. ) Content-type: image/jpeg

Server-script interaction Web server get multiply.php?x=5&y=6 Locate file and run as PHP multiply.php run script “5 * 6 = 30” x=5 y=6

User-script interaction Browser Web server get multiply.php?x=5&y=6 Locate file and run as PHP multiply.php PHP processor run script “5 * 6 = 30” 5 * 6 = 30 HTML MIME User Enter data Read output get form.htm Click link Locate file Calculate button x=5 y=6 Display form.htm Display generated HTML page

form.htm <!-- this is not XHTML standard because it lacks headers but it does have all attribute values in quotes and all tags are terminated --> x = y =

Browser-Server interaction Browser Web server get multiply.php?x=5&y=6 Locate file and run as PHP 5 * 6 = 30 HTML MIME Click button

URL Relative URL –multiply.php?x=5&y=6 Absolute URL – (my Home machine running IIS) – (the development server) – hp?x=5&y=6 (the public production server) hp?x=5&y=6

Server-script interaction Web server get multiply.php?x=5&y=6 Locate file and run as PHP multiply.php PHP processor run script “5 * 6 = 30” x=5 y=6

Server-PHP interaction Parameters –GET and POST Parameters available as variables of the same name $x, $y (deprecated but used in my code ) in an array $_GET[‘x’] depends on the setup –Parameter values are URL-Decoded Implicit Parameters –In addition to the user-defined parameters, other data is available about the client and about the server –$PHP_SELF is the program name –$HTTP_USER_AGENT is the browser Reply –HTML goes through to output – script is executed as PHP Print or echo statements add to output –All output returned to Server –Other kinds of output (JPEG, GIF.. ) require different headers to be output

Multiply.php script <?php /* function: to multiply the two input numbers and display the result input: x, y : numbers author: Chris Wallace 9 Oct 204 */ // calculate the result // no typing or declaring new variable // also implicit conversion of string to number $prod = $x * $y; // values of variables interpolated into the string print "$x * $y = $prod"; ?>

The generated HTML 5 * 6 = 30 This simple text is not XHTML compliant of course. HTML to provide a readable page can be added around the PHP 5 * 6 Note that we have added the name/value pairs to the URL – not very useful here obviously. some pairs can be in the action URL of a form, some in input fields The script multiply2.php includes the original PHP script within an HTML page

Multiply2.php Program composition with ‘require’ PHP introduction - multiply script PHP introduction

‘Sticky Forms’ Poor interface -user must to go back to original form to change the data and re- calculate. Key idea: –Combine form and calculator into one script –Do calculation (if required) first –Put inputs as defaults in form Simple combination of form and script – Calculate Product Calculate Product

multiply3.php Combined form and calculator <?php // first compute the output, but only if data has been input if( isset($calc)) { // data was submitted $prod = $x * $y; } else { // set defaults $x=0;$y=0;$prod=0; } ?> "> x = "/> y= "/> x * y =

Initial Form x = y= x * y = 0

Form with Entered Values x = y= x * y =

Forms processing Interface and presentation can be easily improved – Calculate Product Calculate Product Script can do validation and add error messages to the form where fields are missing or invalid. Where to do the processing?: –on Client in Javascript –on Server in PHP or Java What factors do you need to consider to decide?

SMS version Now nearly the same application with an SMS presentation layer. For variety, I’ve generalised to allow any number of numbers to be multiplied together Text –MUL num1 num2 num3 … –To: Eg. –MUL Reply –34 x 56 x 78 =

SMS to script interface Script ‘plugs’ into SMS server Must obey the protocol: –Parameters Text From Code –Reply text: Reply: Entry required in routing file: –MUL mult.php mult.php

smsmult.php <?php $text=trim($text); // to remove trailing whitespace $nums = split(" +",$text); // split the string apart on spaces // + means 1 or more occurances $prod=1; foreach ($nums as $number){ $prod=$prod*$number; // accumulate the product } $numlist = join(" x ",$nums); // join the numbers with ' x ' print "Reply: $numlist = $prod"; ?>