http:en'wikipedia'orgwikiHttp - PowerPoint PPT Presentation

1 / 78
About This Presentation
Title:

http:en'wikipedia'orgwikiHttp

Description:

http://en.wikipedia.org/wiki/Http. Hypertext Transfer Protocol (HTTP) is a ... for the transfer of information on the Internet. ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0

less

Transcript and Presenter's Notes

Title: http:en'wikipedia'orgwikiHttp


1
http//en.wikipedia.org/wiki/Http
Hypertext Transfer Protocol (HTTP) is a
communications protocol for the transfer of
information on the Internet. Its use for
retrieving inter-linked text documents
(hypertext) led to the establishment of the
World Wide Web. HTTP development was coordinated
by the World Wide Web Consortium and the
Internet Engineering Task Force (IETF),
culminating in the publication of a series of
Request for Comments (RFCs), most notably RFC
2616 (June 1999), which defines HTTP/1.1, the
version of HTTP in common use.
2
HTTP is a request/response standard between a
client and a server. A client is the end-user,
the server is the web site. The client making an
HTTP request - using a web browser, spider, or
other end-user tool - is referred to as the user
agent. The responding server - which stores or
creates resources such as HTML files and images -
is called the origin server.
3
Typically, an HTTP client initiates a request.
It establishes a Transmission Control Protocol
(TCP) connection to a particular port on a host
(port 80 by default see List of TCP and UDP port
numbers). An HTTP server listening on that port
waits for the client to send a request message.
Upon receiving the request, the server sends back
a status line, such as "HTTP/1.1 200 OK", and a
message of its own, the body of which is perhaps
the requested file, an error message, or some
other information. Resources to be accessed by
HTTP are identified using Uniform Resource
Identifiers (URIs) (or, more specifically,
Uniform Resource Locators (URLs)) using the http
or https URI schemes.
4
http//en.wikipedia.org/wiki/Html
5
HTML, an initialism of HyperText Markup Language,
is the predominant markup language for Web
pages. It provides a means to describe the
structure of text-based information in a
document by denoting certain text as links,
headings, paragraphs, lists, and so on and to
supplement that text with interactive forms,
embedded images, and other objects. HTML is
written in the form of tags, surrounded by angle
brackets. HTML can also describe, to some
degree, the appearance and semantics of a
document, and can include embedded scripting
language code (such as JavaScript) which can
affect the behavior of Web browsers and other
HTML processors. By convention, HTML format data
files use a file extension .html or .htm.
6
Following is from HTML tutorial at
http//www.w3schools.com/html/html_intro.asp
7
lthtmlgt ltheadgt lttitlegtTitle of pagelt/titlegt lt/headgt
ltbodygt This is my first homepage. ltbgtThis text
is boldlt/bgt lt/bodygt lt/htmlgt Save the file as
"mypage.htm". Start your Internet browser. Select
"Open" (or "Open Page") in the File menu of your
browser. A dialog box will appear. Select
"Browse" (or "Choose File") and locate the HTML
file you just created - "mypage.htm" - select it
and click "Open". Now you should see an address
in the dialog box, for example "C\MyDocuments\myp
age.htm". Click OK, and the browser will display
the page.
8
This is an HTML element ltbgtThis text is
boldlt/bgt The HTML element starts with a start
tag ltbgtThe content of the HTML element is This
text is boldThe HTML element ends with an end
tag lt/bgt The purpose of the ltbgt tag is to define
an HTML element that should be displayed
as bold. This is also an HTML element ltbodygt
This is my first homepage. ltbgtThis text is
boldlt/bgt lt/bodygt This HTML element starts with
the start tag ltbodygt, and ends with the end tag
lt/bodygt. The purpose of the ltbodygt tag is to
define the HTML element that contains the
body of the HTML document.
9
We have just said that HTML tags are not case
sensitive ltBgt means the same as ltbgt. If you
surf the Web, you will notice that plenty of web
sites use uppercase HTML tags in their
source code. We always use lowercase tags.
Why? If you want to follow the latest web
standards, you should always use lowercase tags.
The World Wide Web Consortium (W3C) recommends
lowercase tags in their HTML 4
recommendation, and XHTML (the next
generation HTML) demands lowercase tags.
10
Experiment with html here http//www.w3schools.c
om/html/tryit.asp?filenametryhtml_basic
11
Paragraphs are defined with the ltpgt tag. ltpgtThis
is a paragraphlt/pgt ltpgtThis is another
paragraphlt/pgt HTML automatically adds an extra
blank line before and after a paragraph. Don't
Forget the Closing Tag You might have noticed
that paragraphs can be written without end tags
lt/pgt ltpgtThis is a paragraph ltpgtThis is another
paragraph The example above will work in most
browsers, but don't rely on it. Future version
of HTML will not allow you to skip ANY end
tags. Closing all HTML elements with an end tag
is a future-proof way of writing HTML. It
also makes the code easier to understand (read
and browse) when you mark both where an
element starts and where it ends.
12
Line Breaks The ltbrgt tag is used when you want to
break a line, but don't want to start a new
paragraph. The ltbrgt tag forces a line break
wherever you place it. ltpgtThis ltbrgt is a
paraltbrgtgraph with line breakslt/pgt Try it
yourself The ltbrgt tag is an empty tag. It has no
end tag like lt/brgt, since a closing tag
doesn't make any sense.
13
ltbrgt or ltbr /gt More and more often you will see
the ltbrgt tag written like this ltbr /gt Because
the ltbrgt tag has no end tag (or closing tag),
it breaks one of the rules for future HTML
(the XML based XHTML), namely that all
elements must be closed. Writing it like ltbr /gt
is a future proof way of closing (or
ending) the tag inside the opening tag,
accepted by both HTML and XML.
14
Comments in HTML The comment tag is used to
insert a comment in the HTML source code. A
comment will be ignored by the browser. You can
use comments to explain your code, which
can help you when you edit the source code at a
later date. lt!-- This is a comment --gt Note
that you need an exclamation point after the
opening bracket, but not before the closing
bracket.
15
Recap on HTML Elements Each HTML element has an
element name (body, h1, p, br) The start tag is
the name surrounded by angle brackets
lth1gt The end tag is a slash and the name
surrounded by angle brackets lt/h1gt The
element content occurs between the start tag and
the end tag Some HTML elements have no
content Some HTML elements have no end tag
16
There is quite a bit more in this HTML Tutorial,
but we will not go through that now.
17
http//en.wikipedia.org/wiki/Php
PHP is a computer scripting language. Originally
designed for producing dynamic web pages, it has
evolved to include a command line interface
capability and can be used in standalone
graphical applications.2 While PHP was
originally created by Rasmus Lerdorf in 1995,
the main implementation of PHP is now produced
by The PHP Group and serves as the de facto
standard for PHP as there is no formal
specification.3 Released under the PHP
License, the Free Software Foundation considers
it to be free software.4
18
PHP is a widely used general-purpose scripting
language that is especially suited for web
development and can be embedded into HTML. It
generally runs on a web server, taking PHP code
as its input and creating web pages as output.
It can be deployed on most web servers and on
almost every operating system and platform free
of charge.5
19
PHP primarily acts as a filter,31 taking
input from a file or stream containing text
and/or PHP instructions and outputs another
stream of data most commonly the output will
be HTML.
20
Originally designed to create dynamic web pages,
PHP's principal focus is server-side
scripting,35 and it is similar to other
server-side scripting languages that provide
dynamic content from a web server to a client,
such as Microsoft's ASP.NET system, Sun
Microsystems' JavaServer Pages,36 and mod_perl.

21
PHP has also attracted the development of many
frameworks that provide building blocks and a
design structure to promote rapid application
development (RAD). Some of these include CakePHP,
PRADO, Symfony and Zend Framework, offering
features similar to other web application
frameworks. The LAMP architecture has become
popular in the web industry as a way of deploying
web applications. PHP is commonly used as the P
in this bundle alongside Linux, Apache and MySQL,
although the P may also refer to Python or Perl.
22
As of April 2007, over 20 million Internet
domains were hosted on servers with PHP
installed, and PHP was recorded as the most
popular Apache module.37 Significant websites
are written in PHP including the user-facing
portion of Facebook,3839 and Wikipedia
(Mediawiki).40
23
Following is from PHP tutorial http//www.htmlgo
odies.com/beyond/php/article.php/3472431
24
Start up Apache and PHP http//localhost Select
phpinfo() Find document_root
25
lthtmlgtltheadgtlttitlegtPHP Testlt/titlegtlt/headgtltbod
ygtlt?php phpinfo() ?gtlt/bodygtlt/htmlgt Save as
first.htm at document root. http//localhost/first
.htm Save as first.php at document
root. http//localhost/first.php
26
each statement in your PHP code is ended with a
semicolon.  Leaving this semicolon off is a
common syntax error and when something
isn't working the way you expect it to
should be one of the first things you
check. Whitespace (spaces, tabs and newlines)
are ignored in the syntax of PHP.  These three
examples are completely equivalent lt?php
phpinfo() ?gt lt?php     phpinfo()     ?gt lt?php
phpinfo()?gt
27
As in all forms of programming, adding comments
to you code is a very useful idea.  Make
your code self-documenting and you will love
yourself later when you come back to if
after having forgotten why you did things
a certain way!
28
Here are some examples lt?phpphpinfo()/  This
is a      multi-line comment following     the
C language style of comments./?gt lt?php  //
this is a C style comment on the one code
linephpinfo()?gt lt?php  this is a shell
script style comment on the one code
linephpinfo()?gt
29
We continue now by creating a simple order form. 
The processing of forms like this is one of the
more common things to be done with server side
languages including PHP.  For our example we have
chosen the component order form from the Acme
Widget Company (of course!)  Here's the code for
the entire form
30
lthtmlgtltheadgtltmeta http-equiv"Content-Type"
content"text/html charsetwindows-1252"gtlttitlegt
Acme Widget Companylt/titlegtlt/headgtltbody
style"font-family Arial"gtlth1gtltbrgtAcme Widget
Companylt/h1gtltpgtComponent Order Formlt/pgt
31
ltFORM ACTION"processorder.php"
methodpostgtlttable border0gtlttrgtlttd
width150gtItemltbrgtnbsplt/tdgtlttd
width15gtQuantityltbrgtnbsplt/tdgtlt/trgtlttrgtlttdgtB
aseslt/tdgtlttd align"center"gtltinput type"text"
name"qtybases" size"3" maxlength"3"gtlt/tdgtlt/trgt
lttrgtlttdgtStemslt/tdgt
32
lttd align"center"gtltinput type"text"
name"qtystems" size"3" maxlength"3"gtlt/tdgtlt/trgt
lttrgtlttdgtTopslt/tdgtlttd align"center"gtltinput
type"text" name"qtytops" size"3"
maxlength"3"gtlt/tdgtlt/trgtlttrgtlttd colspan"2"
align"center"gtltbrgtltinput type"submit"
value"Enter Order"gtlt/tdgtlt/trgtlt/tablegtlt/formgt
lt/bodygtlt/htmlgt
33
You can click here to see what this form looks
like in your browser. http//www.htmlgoodies.com/l
egacy/beyond/php/orderform.html Now let's break
it down.  As with our last example, most of the
code you see is ordinary HTML. 
34
Notice, however, that the ACTION on the FORM
statement points to a PHP file called
processorder.php (the capitals we've used here
are only to highlight to code we're talking about
- it doesn't make any difference whether you use
capitals or lowercase letters, except that the
filename may be case sensitive if your site is
hosted on a Unix/Linux system.). When the user
hits the "enter order" button, the file whose
name (URL) appears in the ACTION statement will
be loaded and the data the user typed into the
form elements will be passed to it.  The data
will be identified to that file by the field
names used on the form, here "qtybases",
"qtystems"  and "qtytops".  For this reason it's
a good idea to use easily recognized and
meaningful names, such as ours are.
35
There's really no PHP code in this form (which is
why it's in a file named with a .html extension)
so we'll move right along to the file that will
process our order.
36
Our order form sent its data to a file called
processorder.php via the instruction
ACTION"processorder.php" methodpost   This is
the content of that file   lthtmlgtltheadgtltmeta
http-equiv"Content-Type" content"text/html
charsetwindows-1252"gtlttitlegtAcme Widget
Companylt/titlegtlt/headgtltbody style"font-family
Arial"gtlth1gtltbrgtAcme Widget Companylt/h1gtltpgtnbsp
lt/pgt
37
lt?php qtybases _POST'qtybases'qtystems
_POST'qtystems'qtytops _POST'qtytops'
?gtltpgtThank you!lt/pgtltpgtYour order
forlt/pgtlt?php echo qtybases.'
basesltbrgt'echo qtystems.' stemsltbrgt'echo
qtytops.' topsltbrgt'?gtltpgtwas
processed.lt/pgtlt/bodygtlt/htmlgt 
38
In here there's plenty of interesting PHP code to
take a look at!  We'll start with that first
piece of PHP codeqtybases
_POST'qtybases'qtystems
_POST'qtystems'qtytops _POST'qtytops'
(To make life easier, I've left off the opening
and closing tags when looking at the code itself
I'll continue like that throughout this
series.)   Each of these statements is an
"assignment" instruction.  The equal sign in
the middle designates it as such and tells PHP to
"make the value of this Equal to the value of
that."  In this case we're making the value of
one variable equal to the value of another
variable (a "variable" is a data element whose
value can change, as opposed to a "constant"
which is a data element whose value can not
change.)  
39
The variables on the left, qtybases for example,
are variable fields that are being dynamically
defined by these statements.  This means that
no other statement was needed to create the
variable qtybases it's being defined right
here.  Those variables are being set to the
values of some "POST" variables.  "POST"
variables are those that are passed down from the
preceding form by means of the POST method
(remember the statement ltFORM ACTION"processorder
.php" methodpostgt in the form.)  We'll get
into more detail about these variables later for
now suffice it to say that this format, using the
names that were used in the calling form, will
pick up the variables being passed down.  
40
Then there's that group of echo statements.
"Echo" works like a "print here" command. 
Remember that the PHP processor is going to
interpret the PHP code in this page and then send
the page down to the client browser.  Whatever
the echo prints out becomes part of the resulting
page.  Each of these echo statements prints out
the value of a variable and a text string
enclosed in quotes. 
41
Look closely and you'll see a period between the
two  This tells PHP to concatenate the two
strings (the value of the variable and the quoted
string) together.  Thus, if qtybases has a
value of 5 then the first echo statement will
return this 5 basesltbrgt which, on the
resulting web page, will show up as "5 bases"
followed by a line break.   Try  it out on our
example. http//www.htmlgoodies.com/legacy/beyond/
php/orderform.html
42
Variables hold one or another "type" of
information.  PHP is "loosely typed," meaning
that the type of information to be held in a
particular variable can change on the fly. 
Changing on the fly means that if you start with
a variable holding numerical data and use it in
calculations, for example, and then write an
instruction to put text into it, PHP will then
consider it to be a text variable. Here are the
main data types used in PHP Integer whole
numbers Double real numbers String strings
of characters (text, etc.) Boolean
true/false Array a set or group of variables of
the same type Object class instances (more
later!)
43
An array needs a few words at this point.  A
simple example of an array would be a string
array called month.  There could be twelve in
the set and they could have the values January,
February etc.  To reference the first of the
set we use an index value thus month(1) In our
example this would refer to array element with a
value of January
44
The index could also be a variable,
thus monthnum 2 echo month(monthnum) Ass
uming the array had been defined with the values
descried in our example, this would
echo February 
45
You've probably heard of type casting, but maybe
not the kind I'm thinking of here!  This has
nothing to do with thespian arts - type casting
in PHP means telling PHP to treat a variable of
one type as if it was another (without actually
changing its type.)  It doesn't really matter
right here why you'd want to do that - it'll
become clearer later.  For now, just take a
look at this example quantity 0amount
(double)quantity quantity is set up as an
integer with a value of zero.  The next line
treats quantity as a double type and assigns its
value to amount.  amount is now a double with
a value of zero and quantity is still an integer
with a value of zero.
46
In PHP you can even use a variable as the name of
a variable.  Take a look at this varname
'quantity' varname 5 The second line uses
the varname variable in the name of the variable
being assigned the value of 5.  Consequently
the variable quantity is assigned the value
5.  It does exactly the same thing as quantity
5
47
In PHP there are two types of expression for us
to look at. One is something called a "regular
expression", which is used in the manipulation of
text. We'll talk more about them later in the
series. The other is more mathematical in
nature, expressing operations to be performed on
values and variables. Here's a simple example
c a b Assuming a and b are numbers (remember
data types?  -- the result would be different if
they were strings -- more about that later) this
expression would add a and b and put the sum into
c (remember again, that the equals sign here
makes this an assignment instruction.) 
48
Arithmetic Operators
49
Comparison Operators
50
Logical Operators
51
Increment and Decrement Operators
52
The Concatenate Operator I get in trouble all the
time because I ask how this can be considered an
"operator", but trust me, the world thinks it
is!  The concatenate "operator" is a period (full
stop to the English English!)  It simply says
"join this to this", so that parta "This is
part one partb "of a sentence! print
parta.partb prints out "This is part one of a
sentence!
53
Combined Operators There are some combination
operators that you may see used (or may use!) 
There are those who argue that these combination
operators provide an advantage because they
reduce typing and reduce the final size of the
code.  In my humble opinion, however, they don't
represent the way that most of us think of
things, and are therefore somewhat confusing. 
See what you think. You remember from earlier
examples that is an assignment operator a
5 assigns the value 5 to a.   This assignment
can be combined with some other operators like
this a 5 If a already had a value of 5,
then after this instruction it would be 10, as if
the full instruction was a a 5 Valid
combinations include    -    /
54
Precedence and Associativity. Think about this
operation a 7 - 4 1 If the minus happens
before the plus, the result would be 4.  If the
plus happens first, the result is 2.  Since
predictability is essential, an order of
precedence was established, along with something
called associativity.  The order of precedence
establishes a "rank" for operators, where those
with the highest rank will be evaluated first. 
When there are several operators of the same
rank, they will be processed from left to right
if they are left associative, and right to left
if they are right associative.  Some operators,
such as the comparison operators, have neither
left nor right associativity.
55
The increment and decrement operators  ( and
-- ) are right associative, while the others I
have discussed here are left associative.  The
order of precedence, from highest to lowest (with
those of equal precedence on the same line) is as
follows   --  /    - andxoror
56
You can override the order of precedence but
wrapping part of an expression in parentheses. 
The innermost parentheses are processed first, so
that (7 - 4) 1 will give a result of 47 - (4
1) will give a result of 2 2 3 3 will give
a result of 112 (3 3) will also give 11(2
3) 3 will give a result of 15 1 3 3 2
will give a result of 101 ((3 3) 2) will
give a result of 13(1 (3 3)) 2 will give a
result of 14
57
The If Statement The basic decision making
statement, the "if" statement says "if this is
true, do this, else do that".  Its format is like
this if ( condition ) do these instructions
else do these instructions and here's an
example if (age lt 21) print "Minor" else
print "Adult"
58
It is also possible to add a condition to the
"else" side by using "elseif" like this if
(temp gt idealtemp) print "Add cold water"
elseif (temp lt idealtemp) print "Add hot
water" else print "Add more water"
59
The For loop You can create a loop by using a
"for" loop construct (as it is known.)  The "for"
statement says "for a value of x starting here,
until the value of x meets this condition, and
changing the value of x by this amount each time
you process the loop, process this code".  This
could use a little explanation!  Basically, x is
going to serve as a counter.  We give x a start
value, for example 1.  Then we specify a
condition to test before we decide to process the
block of instructions in the loop, for example x
lt 11.  Finally, we specify an amount by which
to change x at the end of processing the block of
instructions, for example, increment by 1.  In
this example, the code would be run ten times,
with x having a value of 1 the first time
through, 2 the second, etc. The last time through
it would have a value of 10. 
60
Here's its format for ( counter's initial
value,  counter's condition test, counter's
increment ) do these instructions and here's
an example for (count 1 count lt 11
count )   tot 2 count   print "2
times count equals tot " This example
prints out the two times table from two times one
to two times ten.  It's worth taking special note
of the fact that the test comes at the beginning
of the loop -- that is, before the code block is
run.  Hence the need for a test for "less than
11" in order to get the tenth iteration to run.
61
The "While" loop Another loop construct is the
"While" loop construct.  The for loop uses a
counter to control the number of iterations of
its code block, but the while loop can use any
kind of condition.   There is an inherent danger
here!  What happens if the condition always
remains true?  The code never stops running --
that's what!  This is known as an infinite loop
and the a sure sign of a programmer error.  PHP
allows a system administrator to defend their
system against this kind of abuse of processor
time by providing a time-out mechanism.  PHP
scripts are typically limited to 30 seconds of
execution time, and will quit with an error at
that point.  It is an important part of the
debugging process to ensure that you don't wind
up with any infinite loops!  That having been
said.....
62
A "while" statement says "while this condition is
true, process this code" and its format is while
( condition ) do these instructions Here's
our two times table as a while loop count
1while ( count lt 11 )   tot 2
count   print "2 times count equals tot
"   count count 1
63
There is a couple of things to take particular
notice of in this example.  Firstly, we had to
include a separate statement to initialize the
count data element because it is not part of the
construct as it would be in a for statement. 
Remember that the condition in a while
statement can be any condition -- I have used a
counter type of condition only to show the
comparison of this construct to the for
construct.  Secondly, and for the same reason,
there has to be a statement in the code block to
increment count (I could also have used  
count   or   count 1  -- I like the format
I used the best because it seems the clearest to
me.)
64
There is also a variant of the while loop that
puts the test for the condition at the end, that
is, after the code block has been processed. 
This, of course, means that the code block will
always run at least once.   This variant is the
"do... while" loop and it says "do this code
block, and while this condition is true, go back
and do it again".  Its format is do these
instructionswhile ( condition )
65
Here's our two times table as a do while
loop count 1do   tot 2 count  
print "2 times count equals tot "   count
count 1while ( count lt 11 )
66
These options show you how you can create program
execution loops in you PHP code.  Which one is
the best to use depends on the particular type of
execution requirement.  You have to think a it
about the flow of logic as you see it, and use
the construct that most closely resembles what
you need.  Another thing to remember is that
you can nest these constructs, by which I mean
that the code block to be run by the construct
could include another loop construct.  Any type
of loop can be contained within any other type of
loop. When you include code within a loop like
this it is a valuable thing to do to indent the
code a couple of spaces like I have done in the
examples above. 
67
What is a Function? In the last part of this
tutorial series we looked at controlling logic
flow in PHP.  This included logic flowing in a
linear fashion, but with loops of logic at
various points and with decision making along the
way.  The overall flow was a straight line -
the loops were processed where they occurred, and
the logic continued along its line from the
beginning of the program routine to its end. 
There are times, however, when a series of
instructions has to be repeated from a variety of
different points within the main routine, or
where a series of instructions needs to be
followed that doesn't really fit within the main
routine. 
68
Variable Scope and Lifetime It's important to
note that if you define a variable within a
function, that variable is only available within
that function it cannot be referenced in another
function or in the main body of your program
code.  This is known as a variable's scope. 
The scope of a variable defined within a
function is confined to that function -- in other
words, it's local to that function. If a
function needs to use a variable that is defined
in the main body of the program, it must
reference it using the "global keyword, like
this function AddingNumbers ( )   global
sum 2 2  sum 0Addnumbers ( )print "2
2 ".sum
69
While the scope of a variable defined in a
function is local to that function, a variable
defined in the main body of code has a global
scope.  The "global" keyword tells PHP to look
for a variable that has been defined outside the
function. There is also the idea of a lifetime
for a variable.  A variable defined within a PHP
program script exists only while that script is
running.  When the script ends, the variable
ceases to exist.  This seems pretty obvious! 
Now apply it to a function  a variable defined
within a function exists only while that function
is being processed when the function ends, the
variable ceases to exist.    Ooooh!  Aaaah-
yes!! 
70
The usefulness of functions is greatly enhanced
by the ability to pass information from the main
body of code to the function and in the opposite
direction, or between one function and another it
is calling  Values that are sent to a function
are called arguments. Passing Argument to a
Function To define arguments that will be passed
to a function, you provide a list of names for
them between the parentheses in the function
statement, like this function Myfunction
(arg1, arg2) and to pass values to the function
as arguments by putting them between the
parentheses following the function's name in the
statement that calls it, like this answer
Myfunction (3, 5)
71
A function returns a result to the calling code
by using the "return keyword, like this return
result When the return statement is processed,
the function terminates and the value of the
variable specified is returned to the calling
code.  The return statement only returns one
variable -- if you need to return more than one
value, you'd have to define and return an array
(we'll be getting into arrays a little later in
this series.) You could have more than one
return statement in your function if, for
example, you had conditional logic (such as "if"
statements) within your function, but only one of
them will ever be processed (since processing it
terminates the function!)
72
An Example Here's an example of a couple of
variables being passed to a function as arguments
with a result returned lthtmlgt ltheadgt lttitlegtFunc
tion Arguments Examplelt/titlegt lt/headgt ltbodygt lth1gt
Showing a Volumelt/h1gt ltbr /gt lt?php function
CalcVol (x, y, z) vol x y
z return vol
73
long 3 wide 4 high 5 print  "The
volume of this object is " . CalcVol(long,
wide, high) . " volumetric units." ?gt lt/bodygt lt
/htmlgt In this example you can see that a
function called CalcVol is being defined, and
that it receives three parameters, x, y z. 
These are being used to specify the lengths of
the three axes of a solid object, which the
function multiplies together to determine the
volume of the object.  The function then returns
the volume to the calling code. The function is
being called from the middle of a print
statement, which passes the three values
contained in the variables long, wide high. 
Thus the print statement will display the result
of the calculation.
74
Lots more of this tutorial continuing
at http//www.htmlgoodies.com/beyond/php/article
.php/3472511
75
http//www.w3.org/TR/html401/interact/forms.html
http//www.w3.org/TR/html401/interact/forms.htmlh
-17.1
76
17.13.3 Processing form data When the user
submits a form (e.g., by activating a submit
button), the user agent processes it as
follows. Step one Identify the successful
controls  Step two Build a form data set  A form
data set is a sequence of control-name/current-val
ue pairs constructed from successful
controls Step three Encode the form data
set  The form data set is then encoded according
to the content type specified by the enctype
attribute of the FORM element.
77
Step four Submit the encoded form data
set  Finally, the encoded data is sent to the
processing agent designated by the action
attribute using the protocol specified by the
method attribute. This specification does not
specify all valid submission methods or content
types that may be used with forms. However, HTML
4 user agents must support the established
conventions in the following cases If the method
is "get" and the action is an HTTP URI, the user
agent takes the value of action, appends a ?' to
it, then appends the form data set, encoded using
the "application/x-www-form-urlencoded" content
type. The user agent then traverses the link to
this URI. In this scenario, form data are
restricted to ASCII codes. If the method is
"post" and the action is an HTTP URI, the user
agent conducts an HTTP "post" transaction using
the value of the action attribute and a message
created according to the content type specified
by the enctype attribute. For any other value of
action or method, behavior is unspecified. User
agents should render the response from the HTTP
"get" and "post" transactions.
78
17.13 Form submission The following sections
explain how user agents submit form data to form
processing agents. 17.13.1 Form submission
method The method attribute of the FORM element
specifies the HTTP method used to send the form
to the processing agent. This attribute may take
two values get With the HTTP "get" method, the
form data set is appended to the URI specified
by the action attribute (with a question-mark
("?") as separator) and this new URI is sent to
the processing agent. post With the HTTP "post"
method, the form data set is included in the
body of the form and sent to the processing
agent. The "get" method should be used when the
form is idempotent (i.e., causes no
side-effects). Many database searches have no
visible side-effects and make ideal applications
for the "get" method. If the service associated
with the processing of a form causes side effects
(for example, if the form modifies a database or
subscription to a service), the "post" method
should be used.
Write a Comment
User Comments (0)
About PowerShow.com