Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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 the two multiplied to together

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

3 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

4 User – Browser interaction User locates desired linklink 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 formresult

5 form.htm Calculator x = y =

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

7 Browser-Server interaction Parameters passed as 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 –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

8 URL Relative URL –multiply.php?x=5&y=6 Absolute URL –http://www.cems.uwe.ac.uk/~cjwallac/apps/calc/ multiply1.php?x=5&y=6http://www.cems.uwe.ac.uk/~cjwallac/apps/calc/ multiply1.php?x=5&y=6

9 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

10 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

11 Server-PHP interaction Parameters –GET and POST Parameters available as in an array $_GET[‘x’] variables of the same name $x, $y (this is no longer meant to be used) depends on the setup –Parameter values are URL-decoded 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

12 Multiply.php script Result <?php /* function: to multiply the two input numbers and display the result input: x, y : numbers */ // 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"; ?>

13 ‘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

14

15 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 =


Download ppt "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."

Similar presentations


Ads by Google