en.wikipedia/wiki/Http - PowerPoint PPT Presentation

benjamin
slide1 l.
Skip this Video
Loading SlideShow in 5 Seconds..
en.wikipedia/wiki/Http PowerPoint Presentation
Download Presentation
en.wikipedia/wiki/Http

play fullscreen
1 / 78
Download Presentation
en.wikipedia/wiki/Http
635 Views
Download Presentation

en.wikipedia/wiki/Http

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  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 httpsURI 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. <html> <head> <title>Title of page</title> </head> <body> This is my first homepage. <b>This text is bold</b> </body> </html> 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\mypage.htm". Click OK, and the browser will display the page.

  8. This is an HTML element: <b>This text is bold</b> The HTML element starts with a start tag: <b>The content of the HTML element is: This text is boldThe HTML element ends with an end tag: </b> The purpose of the <b> tag is to define an HTML element that should be displayed as bold. This is also an HTML element: <body> This is my first homepage. <b>This text is bold</b> </body> This HTML element starts with the start tag <body>, and ends with the end tag </body>. The purpose of the <body> 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: <B> means the same as <b>. 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.com/html/tryit.asp?filename=tryhtml_basic

  11. Paragraphs are defined with the <p> tag. <p>This is a paragraph</p> <p>This is another paragraph</p> 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 </p>: <p>This is a paragraph <p>This 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 <br> tag is used when you want to break a line, but don't want to start a new paragraph. The <br> tag forces a line break wherever you place it. <p>This <br> is a para<br>graph with line breaks</p> Try it yourself The <br> tag is an empty tag. It has no end tag like </br>, since a closing tag doesn't make any sense.

  13. <br> or <br /> More and more often you will see the <br> tag written like this: <br /> Because the <br> 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 <br /> 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. <!-- This is a comment --> 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: <h1> The end tag is a slash and the name surrounded by angle brackets </h1> 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 standalonegraphical 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,[38][39] and Wikipedia (Mediawiki).[40]

  23. Following is from PHP tutorial: http://www.htmlgoodies.com/beyond/php/article.php/3472431

  24. Start up Apache and PHP http://localhost Select phpinfo() Find “document_root”

  25. <html><head><title>PHP Test</title></head><body><?php phpinfo(); ?></body></html> 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: <?php phpinfo(); ?> <?php     phpinfo();     ?> <?php phpinfo();?>

  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: <?phpphpinfo();/*  This is a      multi-line comment following     the C language style of comments.*/?> <?php  // this is a C++ style comment on the one code linephpinfo();?> <?php  # this is a shell script style comment on the one code linephpinfo();?>

  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. <html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Acme Widget Company</title></head><body style="font-family: Arial"><h1><br>Acme Widget Company</h1><p>Component Order Form</p>

  31. <FORM ACTION="processorder.php" method=post><table border=0><tr><td width=150>Item<br>&nbsp;</td><td width=15>Quantity<br>&nbsp;</td></tr><tr><td>Bases</td><td align="center"><input type="text" name="qtybases" size="3" maxlength="3"></td></tr><tr><td>Stems</td>

  32. <td align="center"><input type="text" name="qtystems" size="3" maxlength="3"></td></tr><tr><td>Tops</td><td align="center"><input type="text" name="qtytops" size="3" maxlength="3"></td></tr><tr><td colspan="2" align="center"><br><input type="submit" value="Enter Order"></td></tr></table></form></body></html>

  33. You can click here to see what this form looks like in your browser. http://www.htmlgoodies.com/legacy/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" method=post This is the content of that file: <html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Acme Widget Company</title></head><body style="font-family: Arial"><h1><br>Acme Widget Company</h1><p>&nbsp;</p>

  37. <?php $qtybases = $_POST['qtybases'];$qtystems = $_POST['qtystems'];$qtytops = $_POST['qtytops'];?><p>Thank you!</p><p>Your order for:</p><?php echo $qtybases.' bases<br>';echo $qtystems.' stems<br>';echo $qtytops.' tops<br>';?><p>was processed.</p></body></html>

  38. In here there's plenty of interesting PHP code to take a look at!  We'll start with that first piece of PHP code:$qtybases = $_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 <FORM ACTION="processorder.php" method=post> 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 bases<br> 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); Assuming 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 = 0;$amount = (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: