PHP and MySQL Web Development - P154 pptx

5 200 0
PHP and MySQL Web Development - P154 pptx

Đang tải... (xem toàn văn)

Thông tin tài liệu

737 Further Reading Problems with Headers One minor thing to note in all these scripts is that we need to tell the browser what type of data we are going to send it.We have done this by sending a content-type HTTP header, for example header( 'Content-type: application/msword' ); or header( 'Content-type: application/pdf' ); One thing to be aware of is that browsers deal with these headers inconsistently. In par- ticular, Internet Explorer often chooses to ignore the MIME type and attempt to auto- matically detect the type of file. (This particular problem seems to have improved in recent versions of Internet Explorer.) Some of our headers seemed to cause problems with session control headers.There are a few ways around this.We have found using GET parameters rather than POST or session variable parameters avoids the problem. Another solution is not to use an inline PDF but to get the user to download it instead as shown in the Hello World PDFlib example. You can also avoid problems if you are willing to write two slightly different versions of your code, one for Netscape and one for Internet Explorer. Extending the Project Adding some more realistic assessment tasks to the examination obviously could extend this project, but it is really intended as an example of ways to deliver your own docu- ments. Customized documents that you might want to deliver online could include legal documents, partially filled in order or application forms, or forms needed by government departments. Further Reading We suggest you visit Adobe’s site if you want to know more about the PDF (and FDF) formats: http://www.adobe.com 36 525x ch30 1/24/03 3:40 PM Page 737 36 525x ch30 1/24/03 3:40 PM Page 738 31 Connecting to Web Services with XML and SOAP IN THE LAST FEW YEARS , XML (Extensible Markup Language) has become an important means of communication. In this chapter, we will use Amazon’s new Web Services inter- face to build a shopping cart on our local Web site that uses Amazon as a back end. (We will call this application Tahuayo, which is the name of an Amazonian tributary.) We will use two different methods to do this: SOAP and XML over HTTP.We will use PHP’s XML ( expat) and NuSOAP (SOAP) libraries to implement these two methods. We will discuss the following topics: n Understanding XML and SOAP basics n Using XML to communicate with Amazon n Parsing XML with PHP’s XML library n Caching responses n Talking to Amazon with NuSOAP The Problem We have two goals with this project: The first is to for you to gain an understanding of what XML and SOAP are and how we use them in PHP. The second is to put these technologies to use to communicate with the outside world.We have chosen the new Amazon Web Services program as an interesting example that you might find useful for your own Web site. Amazon has long offered an associate program that allows you to advertise Amazon’s products on your Web site. Users can then follow a link to each product’s page on Amazon’s site. If someone clicks through from your site and then buys that product, you get a small commission. 37 525x ch31 1/24/03 3:35 PM Page 739 740 Chapter 31 Connecting to Web Services with XML and SOAP The Web Services program enables you to use Amazon more as an engine: you can search it and display the results via your own site, or fill a user’s shopping cart directly with the contents of items he has selected while browsing your site. In other words, the customer uses your site until it is time to check out, which he can then do via Amazon. Communications between you and Amazon can take place in two possible ways.The first way is by using XML over HTTP. If, for example, we want to perform a search using this method, you send a normal HTTP request for the information you require and Amazon will respond with an XML document containing the information you requested.You can then parse this XML document with PHP’s XML library and display the search results to the end user. The second way is by using SOAP. SOAP is one of the standard Web Services proto- cols. It used to stand for Simple Object Access Protocol, but recently it was decided that the protocol wasn’t that simple, and that the name was a bit misleading.The result is that the protocol is still called SOAP but it is no longer an acronym. We will build a SOAP client that can send requests to and receive responses from the Amazon SOAP server.These will contain the same information as the responses we get using the XML over HTTP method, but we will use a different approach to extract the data, namely PHP’s SOAP library. Our final goal in this project is to build our own book-selling Web site that uses Amazon as a back end.We will build two alternative versions: one using XML over HTTP and one using SOAP. Understanding XML Let’s spend a few moments talking about XML and Web Services, in case you are not familiar with these concepts. XML is the Extensible Markup Language.The specification is available from the W3C. Lots of information about XML can be found at the W3C’s XML site at http://www.w3.org/XML/. XML is derived from SGML (Standard Generalized Markup Language). If you already know HTML (and we assume by this point in the book that you probably do!), you will have little difficulty with the concepts of XML. XML is a tag-based text format for documents. As an example of an XML document, Listing 31.1 shows one of the responses Amazon sends in response to an XML over HTTP request. Listing 31.1 XML Document Describing the First Edition of This Book <?xml version="1.0" encoding="UTF-8"?> <ProductInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation = "http://xml.amazon.com/schemas2/dev-heavy.xsd"> <Details url="http://www.amazon.com/exec/obidos/redirect? tag=tangledwebdesign%26creative=XXXXXXXXXXXXXX%26 camp=2025%26link_code=xm2%26path=ASIN/0672317842"> 37 525x ch31 1/24/03 3:35 PM Page 740 741 Understanding XML <Asin>0672317842</Asin> <ProductName>PHP and MySQL Web Development</ProductName> <Catalog>Book</Catalog> <Authors> <Author>Luke Welling</Author> <Author>Laura Thomson</Author> </Authors> <ReleaseDate>30 March, 2001</ReleaseDate> <Manufacturer>Sams</Manufacturer> <ImageUrlSmall> http://images.amazon.com/images/P/0672317842.01.THUMBZZZ.jpg </ImageUrlSmall> <ImageUrlMedium> http://images.amazon.com/images/P/0672317842.01.MZZZZZZZ.jpg </ImageUrlMedium> <ImageUrlLarge> http://images.amazon.com/images/P/0672317842.01.LZZZZZZZ.jpg </ImageUrlLarge> <ListPrice>$49.99</ListPrice> <OurPrice>$34.99</OurPrice> <UsedPrice>$31.95</UsedPrice> <ThirdPartyNewPrice>$31.75</ThirdPartyNewPrice> <SalesRank>312</SalesRank> <Lists> <ListId>3KZW1EV9QMB5F</ListId> <ListId>22YCO1IGPIZJ3</ListId> <ListId>Y2I9B362QXVX</ListId> </Lists> <BrowseList> <BrowseNode> <BrowseName>PHP (Computer program language</BrowseName> </BrowseNode> <BrowseNode> <BrowseName>SQL (Computer program language</BrowseName> </BrowseNode> <BrowseNode> <BrowseName>Web sites</BrowseName> </BrowseNode> <BrowseNode> <BrowseName>Design</BrowseName> </BrowseNode> <BrowseNode> <BrowseName>SQL (Computer language)</BrowseName> </BrowseNode> <BrowseNode> <BrowseName>Sql (Programming Language)</BrowseName> </BrowseNode> Listing 31.1 Continued 37 525x ch31 1/24/03 3:35 PM Page 741 . do this: SOAP and XML over HTTP.We will use PHP s XML ( expat) and NuSOAP (SOAP) libraries to implement these two methods. We will discuss the following topics: n Understanding XML and SOAP basics n Using. SOAP is one of the standard Web Services proto- cols. It used to stand for Simple Object Access Protocol, but recently it was decided that the protocol wasn’t that simple, and that the name was. Page 740 741 Understanding XML <Asin>0672317842</Asin> <ProductName> ;PHP and MySQL Web Development& lt;/ProductName> <Catalog>Book</Catalog> <Authors> <Author>Luke

Ngày đăng: 07/07/2014, 03:20

Từ khóa liên quan

Mục lục

  • PHP and MySQL Web Development

  • Copyright

  • Table of Contents

  • Introduction

  • Part I: Using PHP

    • Chapter 1: PHP Crash Course

    • Chapter 2: Storing and Retrieving Data

    • Chapter 3: Using Arrays

    • Chapter 4: String Manipulation and Regular Expressions

    • Chapter 5: Reusing Code and Writing Functions

    • Chapter 6: Object-Oriented PHP

    • Part II: Using MySQL

      • Chapter 7: Designing Your Web Database

      • Chapter 8: Creating Your Web Database

      • Chapter 9: Working with Your MySQL Database

      • Chapter 10: Accessing Your MySQL Database from the Web with PHP

      • Chapter 11: Advanced MySQL

      • Part III: E-commerce and Security

        • Chapter 12: Running an E-commerce Site

        • Chapter 13: E-commerce Security Issues

        • Chapter 14: Implementing Authentication with PHP and MySQL

        • Chapter 15: Implementing Secure Transactions with PHP and MySQL

        • Part IV: Advanced PHP Techniques

          • Chapter 16: Interacting with the File System and the Server

Tài liệu cùng người dùng

Tài liệu liên quan