Professional PHP Programming phần 1

Chia sẻ: Hà Nguyễn Thúy Quỳnh | Ngày: | Loại File: PDF | Số trang:86

lượt xem

Professional PHP Programming phần 1

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Hướng này là L (trái sang phải) nếu số mức độ thậm chí còn và R (phải sang trái) nếu số level là lẻ. Đoạn đều có một mức độ nhúng mặc định, và do đó một hướng mặc định liên kết với nó. Điều này còn được gọi là hướng cơ bản của đoạn văn.

Chủ đề:

Nội dung Text: Professional PHP Programming phần 1

  1. Simpo PDF Merge and Split Unregistered Version -
  2. Simpo PDF Merge and Split Unregistered Version - Professional PHP Programming Jesus Castagnetto Harish Rawat Sascha Schumann Chris Scollo Deepak Veliath Wrox Press Ltd.  1 TEAM FLY PRESENTS
  3. Simpo PDF Merge and Split Unregistered Version - Professional PHP Programming © 1 999 Wrox Press All rights reserved. No part of this book may be reproduced, stored in a retrieval system or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embodied in critical articles or reviews. The authors and publisher have made every effort in the preparation of this book to ensure the accuracy of the information. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, Wrox Press nor its dealers or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. P ublished by Wrox Press Ltd Arden House, 1102 Warwick Road, Acock's Green, Birmingham B27 6BH, UK Printed in USA ISBN 1-861002-96-3 2 TEAM FLY PRESENTS
  4. Simpo PDF Merge and Split Unregistered Version - Trademark Acknowledgements W rox has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Wrox cannot guarantee the accuracy of this information. Credits Authors Technical Reviewers Jesus Castagnetto Matt Allen Harish Rawat Vivek Awasthi Sascha Schumann Gianluca Baldo Chris Scollo Robert Baskerville Deepak Veliath Mathijs Brands Andy Jeffries Additional Material Kristian Kohntopp Mathijs Brands Manuel Lemos Rod Kreisler Samuel Liddcott Brian Moon Brad Marsh Mark Musone Neil Matthews Julian Skinner Sebastian Moerike-Krauz Mark Musone Editors Paul Schreiber Robert FE Shaw Rick Stones Soheb Siddiqi Adrian Sill Julian Skinner Andrew Stopford Adrian Teasdale Development Editor Mark Wilcox Richard Collins Design / Layout Managing Editor Tom Bartlett Paul Cooper Mark Burdett Will Fallon Project Manager Jon Jones Tony Berry John McNulty Index Cover Design Martin Brooks Chris Morris TEAM FLY PRESENTS
  5. Simpo PDF Merge and Split Unregistered Version - About the Authors Jesus M. Castagnetto J esus M. Castagnetto is a Ph.D. Chemist currently working at The Scripps Research Institute as a Postdoctoral Research Associate in the Metalloprotein Structure and Design Group ( ), where he is developing the Metalloprotein Database and Browser ( ) u sing a combination of in-house programs, Java applets/servlets, SQL databases, and PHP3 server-side scripting. Got his PhD from New York University for research in computational, synthetic, and physico-chemical studies of small molecule ligand-metal complexes. Nowadays, he tackles systems that are a "little" bigger: Metalloproteins. Bioinformatics and computational modeling of chemical systems are two of his main areas of interest. In his spare time, (yeah, right!) he hacks awk, PHP, plays way too much with his PalmPilot, and tries not to hurt anybody while doing Shorinji Kempo, or swinging his sword wildly in Iaijutsu class. Harish Rawat H arish Rawat is a Software Developer at the Oracle Corporation. He has seven years of experience in systems programming. His technical areas of interest include XML, Java, and Network protocols. I would like to thank Arnab and Pankaj for their invaluable suggestions in designing the Shopping Cart Application. I would also like to thank people at Oracle India Development Center for their encouragement and support throughout the writing process. Sascha Schumann S ascha Schumann is a member of the PHP Group and the Apache Software Foundation. He currently studies at Gymnasium Letmathe. Sascha is the architect of many PHP modules (including but not limited to: DBA, Session management, mcrypt, mhash), has connected PHP with AOLserver, and provides general PHP support and custom PHP extensions to organizations employing PHP. Sascha also maintains mhash, which is an open source software for creating cryptological digests (so called hashes). Christopher Scollo C hristopher Scollo is the co-founder and president of Taurix, a software development company based in New Brunswick, New Jersey. When not developing web applications, teaching web courses, or drowning in web periodicals, he hikes and eats. (Potatoes are a passion.) In addition to programming languages, he also enjoys human languages and speaks English, German, French, and Italian to varying degrees. He lives in Princeton, New Jersey with his wife, Nicole Bator. Deepak Veliath D eepak Veliath is currently working for the Oracle Corporation in Bangalore, India. He has been following PHP for a year now. Favorite OS - Linux. When not writing books, busy making plots to kill editors in their sleep :) 4 TEAM FLY PRESENTS
  6. Simpo PDF Merge and Split Unregistered Version - Table of Contents I. Introduction 1. About this book 2. Downloading, installing, configuring PHP 3. Programming in a Web environment II. The Language 4. Variables and data types 5. Operators 6. Expressions and Statements if ... else ... elseif switch while and do ... while for Error! Bookmark not defined. require and include exit Error! Bookmark not defined. 7. Functions How They Work Passing Arguments Variable Scope and Lifetime Nested Functions and Recursion Assigning Functions to Variables 8. Arrays Starting Simply Looping Through an Array A Sequentially Indexed Array Non-sequentially Indexed Arrays A Few Words About next() and prev() array_walk() Associative Arrays Multi-Dimensional Arrays Sorting Functions Using Arrays with Form Elements 9. Objects and OOP Object-Oriented Programming Defining a Class Instantiating the Class Constructors Inheritance 10. String manipulation and regular expressions III. Applying PHP 11. Non-relational databases What is a database? Databases and CSV dbm - a fast, record-based, flat-file database i TEAM FLY PRESENTS
  7. Simpo PDF Merge and Split Unregistered Version - Another interface to dbm - DBA Our telephone book interface Error! Bookmark not defined. 12. SQL DBMS engines 13. Using LDAP 14. Serving XML documents 15. Graphic content creation 16. PHP connectivity Utilizing TCP The whois function The Frontend Extending the Frontend Is my domain still available? A web client 17. Sending E-mail 18. Cookies What are cookies? Cookies in PHP Getting started Deleting a cookie Common pitfalls What is your name? 19. Error handling and debugging 20. Security issues 21. Magic with quotes What are magic quotes? Defining the scope Magic quotes explained Sybase extension Applying magic_quotes Two helper functions An alternative approach Summary 22. Templates IV. Sample Applications 23. A shopping cart application 24. An OO site V. Advanced Topics 25. Version migration 26. When should I avoid regular expression functions VI. Appendix A. Reference B. Open Source Software C. PHP in non-UNIX environments D. Notes on PHP4/Zend Basic concepts ii TEAM FLY PRESENTS
  8. Simpo PDF Merge and Split Unregistered Version - The binary compiler The optimizer New features in PHP4 PHP4 and overall portability E. Other Resources iii TEAM FLY PRESENTS
  9. Simpo PDF Merge and Split Unregistered Version - List of Examples 11-1. edit_form() function 16-1. Initiating a TCP connection 16-2. Exchanging messages with a SMTP server 16-3. whois_request() function 16-4. Simple whois frontend (HTML code) 16-5. Simple whois frontend (PHP code) 16-6. Source code of the simple whois front-end 16-7. Allowing server choice 16-8. Changed PHP code 16-9. a function to tell the TLD 16-10. using an array to store information about whois server 16-11. is_domain_available 16-12. http class framework 16-13. Full http class 16-14. Using the http class 18-1. counting the hits per visitor 18-2. setcookie fails due to sent data before it 18-3. specifying the expire time 18-4. Deleting the cookie username 18-5. deleting and setting a new cookie 18-6. Identifying a visitor 21-1. addslashes() 21-2. output 21-3. output with enabled magic_quotes_sybase 21-4. The ugly way 21-5. automating the conversion process 21-6. using get_magic_quotes_gpc 21-7. using magic_quotes_runtime effectively 21-8. applying stripslashes() 21-9. two helper function 21-10. using sprintf() iv TEAM FLY PRESENTS
  10. Simpo PDF Merge and Split Unregistered Version - Introduction O ver the past years, the Internet has gone from the preserve of academics to the cutting edge of business. A large part of this has been driven by the growth of the Web, with its graphical browsers and high media profile. The change from static HTML pages to dynamic, user interactive presentations has been achieved largely by the introduction of scripting technologies. Working with the usual markup language of a web page, scripting languages enable clients to demand specific information from their servers, and their servers, in turn, to receive important user input in order to process and display data on demand. In the forefront of this advancement has been the Open Source community, dedicated in providing web- based solutions purely for the love of the technology itself. Open source is not only about free software (though not everything is free anyway), but it is about, as the name suggests, being open about the source of the code. Having free access to the source means that authors are forced to keep to standards. If these are not maintained, the deviation is labeled a bug, and if the author doesn't fix it, someone else will. Large numbers of independent programmers being able to understand what a program does, and ensuring that standards are maintained, prevents the author from being able to exploit the user, as happens in the commercial software world. What Does This Book Cover? P HP, the subject of this book, is an open source server-side scripting language that has taken web-based development to a new level of sophistication. In this book we will show you what PHP is, how it simplifies server-side scripting and adds to the functionality of your web pages. In particular, we'll be looking at the following areas: T he PHP language structure and syntax, including its data types, operators, statements and ❑ functions; T he process of installing the scripting engine onyour server; ❑ T he myriad of PHP modules that greatly enhance its capabilities; ❑ S erver Side Programming ❑ P ractical case study examples of PHP in action. ❑ TEAM FLY PRESENTS
  11. Simpo PDF Merge and Split Unregistered Version - Who Should Read This Book? T his book is for anyone who has to implement web-based applications that go beyond simple static pages. If you are attempting to build a database-driven site, or you are new to the whole "dynamic web content generation paradigm", or just want to make some nifty server-side scripts, read this book. If you are an experienced developer that has used until now only product ‘ABC’ that works for the ‘Kewl-OS’ platform, but feel the need to build solutions that are more portable and that can be developed in a short period of time, read this book. We assume that you have some basic knowledge of web technologies. You should be comfortable with writing HTML, have experience with writing programs in any of the many scripting or programming languages, and have some understanding on how a web-based distributed information system works. We will assume also that you have at least conceptual familiarity with databases, although a good knowledge of these systems will surely make it easier to comprehend some of the material in the book (in particular the examples in the databases and the shopping cart application chapters). Technology Requirements F or server-side programming you will need a web server on your machine. This can be IIS on a Windows platform, or something like Apache, or Xitami, for other operating systems. Apache dominates the web server scene, currently powering 60% of the Web. In order to use the server-side scripting tool you will need to install and configure the PHP language interpreter on your server. We will be stepping through this process early in the book. For the client, you have a free choice. PHP is effective on both Internet Explorer and Netscape Communicator, as well as any of the other web browsers that are available. If you want to be able to run all the code, you should also have access to a relational database. Your choice for this is quite wide and explained later in the book. We have chosen to use MySQL throughout the book. For programming itself, all you need is a good text editor, like NotePad, gnotepad or eMacs. Scripting pages are simply text files, often written embedded within the markup language that generates the web page. Conventions Used in This Book W e have used a number of different styles of text and layout in the book to help differentiate between the different kinds of information. Here are examples of the styles we use and an explanation of what they mean: A dvice, hints, and background information comes indented and italicized, like this. I mportant information comes in boxes like this. B ullets are also indented, and appear with a little box marking each new bullet point, like this: I mportant W ords a re in a bold type font ❑ TEAM FLY PRESENTS
  12. Simpo PDF Merge and Split Unregistered Version - W ords that appear on the screen in menus like the F ile o r W indow a re in a similar font to the ❑ one that you see on screen K eys that you press on the keyboard, like Ctrl a nd Enter, are in italics ❑ C ode has several fonts. If it's a word that we're talking about in the text, for example when ❑ discussing the F or...Next l oop, it's in a bold font. If it's a block of code that you can type in as a program and run, then it's also in a gray box: S ometimes you'll see code in a mixture of styles, like this: ❑ T he code with a white background is code we've already looked at and that we don't wish to examine further. These formats are designed to make sure that you know what it is you're looking at. We hope they make life easier. Tell Us What You Think W e've worked hard on this book to make it useful. We've tried to understand what you're willing to exchange your hard-earned money for, and we've tried to make the book live up to your expectations. Please let us know what you think about this book. Tell us what we did wrong, and what we did right. This isn't just marketing flannel: we really do huddle around the email to find out what you think. If you don't believe it, then send us a note. We'll answer, and we'll take whatever you say on board for future editions. The easiest way is to use email: f Y ou can also find more details about Wrox Press on our web site. There, you'll find the code from our latest books, sneak previews of forthcoming titles, and information about the authors and editors. You can order Wrox titles directly from the site, or find out where your nearest local bookstore with Wrox titles is located. TEAM FLY PRESENTS
  13. Simpo PDF Merge and Split Unregistered Version - Customer Support I f you find a mistake, please have a look at the errata page for this book on our web site first. If you can't find an answer there, tell us about the problem and we'll do everything we can to answer promptly! Appendix H outlines how you can submit an errata in much greater detail. Just send us an email: s o r fill in the form on our web site: h ttp:// TEAM FLY PRESENTS
  14. Simpo PDF Merge and Split Unregistered Version - 1 What Is PHP? T he World Wide Web has changed very fast in so many ways. Sometimes it seems like yesterday that a little known markup language with a strange name HTML (Hyper Text Markup Language) was used by some physicists to link scientific documents at a group of CERN servers. It was wondrous to read some text somewhere in the world with just a simple program, and what is more information in the document could magically transport you to another one with related information. And this spread relatively quickly to other sciences. Text-only interfaces were the norm, and simplicity of accessing information content the most important part of the equation. Text documents with a small set of tags and a simple server setup was all you needed to inform your colleagues and share the knowledge, independently of whether the organic chemist at the other end was using his trusty Mac, or the theoretician was using her Unix box, or the impoverished graduate was using a second or third hand PC running very flaky TCP/IP software. Nowadays we expect more, much more than this. We expect a web site with lots of information, and a good presentation, but we do not want to be distracted by a difficult interface. The information should be easy to find, and it should be current. A clean and dynamic web site is a great asset for the user and for the information provider. Long gone (fortunately) are the days of garish-looking web sites with blinky thingies, lots of animated images that usually were hiding a shallow content depth. We want information, we want it 5 minutes ago and we want it in the way we like it. A modern web site is not just a web server; it also includes a way of storing data and querying (a SQL database perhaps), a way of processing the requests from the user and creating documents with the appropriate information. Many are the options open to the web developer, but not all of them as open and general as others. We should not only consider the immediate task at hand of creating a site with dynamic content, we need to be sure that we can still be providing the said content independently of the changes in hardware or software technology. We want to try and insure ourselves against future technology changes, dramatically reduce our license costs, keep our hardware budget under control, and yet be portable to different web servers and operating systems. We also want some assurance that we can do something about that killer bug we just think we found in our web server or scripting environment, be able to understand (if we want to) TEAM FLY PRESENTS
  15. Simpo PDF Merge and Split Unregistered Version - h ow the scripting works, and be able to modify the behavior of our web server or scripting host to meat some particularly unusual need. Open source products will be your best assurance that your application that works now in the "Super-Turbo Hexium IX" machine of today, will work in the "Nanotech Cube Aleph" of tomorrow (I am exaggerating just a wee bit). Enter PHP P HP (acronym for: PHP Hypertext Preprocessor), is a server-side embedded scripting language. This means that it works within an HTML document to confer to it the capacity of generating content on demand. You can convert your site into a web application, not just a collection of static pages with information that may not get updated quite so often, which may be alright for a "personal" web site (yes, we all have made such a beast), but not for one that is going to be used for business or for education. You may be asking "But, why PHP? There are so many other options like ASP, Cold Fusion, Perl, Java, Python, even good old shell/awk/sed scripts?", and the answer will be: simplicity, an almost natural way of using databases and platform independence. And did I mention it was open source? Of course general scripting or programming languages like Perl, Python, etc. have also platform independence, and are open source. They are great languages, and sometimes an overkill for what you need, like using a concrete mixer to make scrambled eggs. PHP was designed to work on the web, and in this ambit it excels; connecting and querying a database is a simple task that can be handled in 2 or 3 lines of code. The PHP scripting engine is well optimized for the response times needed on web applications, it can even be part of the web server itself improving the throughput even more. If it were only a matter of improving the speed of the scripts, then PHP will be one of many solutions. But there is more to the PHP equation than that. There is the simplicity and robustness of the language and the scripting engine. There is the connectivity to an ever increasing number of database servers, the shorter development cycles and the ease (encouraged by the syntaxes and constructs) of creating modular and reusable components. You can perform tasks as simple as creating a feedback form that sends an e-mail to the web maintainer, to a whole database driven document management system (like Midgard, h ttp:// ), to helpdesk or bug tracking systems (like Keystone, h ttp:// ), to a shopping cart application (like FishCartSQL, h ttp:// ), to what would be considered "middle-ware" packages without the need for extra languages or frameworks, and whole libraries for quick and flexible development (PHPLIB, h ttp://phplib Then there is the support from a widely distributed and cooperative community, with several source repositories (like PHP Code Exchange, h ttp:// o r Berber's WeberDev h ttp:// ), many sites with tutorials (PHPBuilder, h ttp:// ; PHPWizard, h ttp:// , WebMonkey, etc.) and thriving (high volume) mailing lists. And did I mention that it is open source? There’s no more waiting until the next release for a feature to be added or a bug to get fixed. Just take the source, make your modifications and there you are, instant customization and complete control. No more guessing at whether a particular function or feature is insecure, the code does not lie. And who TEAM FLY PRESENTS
  16. Simpo PDF Merge and Split Unregistered Version - k nows, maybe your modification gets to be so popular that others may want to use it (hey! instant fame). And you cannot beat the total price for a development environment using the combination of Linux, Apache, MySQL and PHP, not only cheaper than other more proprietary environments, but also more stable and robust. As Eric Raymond said "given enough eyes, all bugs are shallow". It All Began... S ome time in 1994 when Rasmus Lerdorf put together a bunch of Perl scripts to track down who was looking at his resume. Little by little, people started to get interested in the scripts, and they were later released as a package "Personal Home Page" tools (the first meaning of PHP). In view of the interest, he wrote a scripting engine and incorporated another tool to parse input from HTML forms: FI, Form Interpreter, thus creating what was called variously PHP/FI or PHP2. This was done around mid 1995. Soon, people started to use these tools to do more complicated things, and the development changed from just one person, to a group of core developers in charge of the project and its organization. This was the beginning of PHP3. This group of developers (Rasmus Lerdorf, Andi Gutmans, Zeev Suraski, Stig Bakken, Shane Caraveo, and Jim Winstead), improved and extended the scripting engine and added a simple API that will allow other programmers the liberty to add more functionality to the language by writing modules for it. The language's syntax was also refined, with constructs that will be familiar for people coming from object oriented or procedural languages. If you know C, C++ or Java, or have done even some shell/awk scripting, or written a Pascal or VBasic program, learning the basic PHP constructs will be a breeze. The PHP language features the usual complement of control structures, operators, variable types, function declarations and class/object declarations that we have been accustomed to expect from any compiled or interpreted language, and yet it also has features of its own. For example, in C you employ pointers, in other scripting languages this can be cumbersome or even not possible, but in PHP this is just one use of variable variables (discussed in detail later in the book), as the code below shows: $peru = array("domain"=>"pe", "capital"=>"Lima"); $japan = array("domain"=>"jp", "capital"=>"Tokyo"); function show ( $country ) { echo "Internet domain = ".${$country}["domain"]."\n"; echo "Capital city = ".${$country}["capital"]."\n"; } show ("peru"); // Prints: // Internet domain = pe // Capital city = Lima show ("japan"); // Prints: // Internet domain = jp // Capital city = Tokyo T he trick is in the $ {$country}[] c all, which in turn is equivalent to using $ peru[] o r $ japan[] . But that is not all, what if you want to make a function that uses another one for comparing a couple of items. An idea similar to the one shown above allows us to pass different comparison functions in the main function parameters: TEAM FLY PRESENTS
  17. Simpo PDF Merge and Split Unregistered Version - function bigger($x, $y, $comp_func) { if ( $comp_func($x, $y) ) { $out = "Item ".$x." is bigger than ".$y; } else { $out = "Item ".$x." is not bigger than ".$y; } return $out; } bigger(2, 1, "num_comp"); // will use the function num_comp() to compare the numbers bigger("epsilon", "gamma", "greek_comp"); // will compare the strings as names of greek alphabet characters I n this way making general handling routines is simpler, and no, there is no typo above, it is $ comp_func a nd not $ $comp_func , think a little about it and you will see why. Don’t worry if much of the above doesn’t make sense at this moment. These examples are just a taste of what is to come in the rest of the book and will be fully explained. And the Current Situation is... P HP version 4 (PHP4), based on the Zend engine (details at h ttp:// ). This scripting engine has been designed from the ground up to be easily embeddable in different applications. PHP4 is the first application using the Zend engine, but it could also be included in other packages, for example in MySQL (which could be a good way to enable stored procedures in that database). There is already a beta version of PHP4 (beta 3 when this book was written). I will recommend a visit to the Zend web site for more information; particularly tantalizing is the possibility of using COM and perhaps CORBA with this engine. It is also easy to note a trend towards more and more sites using PHP for their scripting needs. The statistics (available at the main PHP site's usage page, h ttp:// ; courtesy of Netcraft, h ttp:// ), show a continuous increase in the total number of domains and IPs using PHP as an internal Apache module (about 1,000,000 virtual servers). There is also a good number of sites using PHP as a stand-alone module and these will not show in the surveys that Netcraft conducts. Notable is also that mod_PHP (as the corresponding Apache module is called) is the most popular module for the most popular web server in the Internet (E-Soft Inc.'s web survey, h ttp://www.e- /). Even a cautious forecast will predict a steady increase of the usage of PHP, even more when the final PHP4 version appears with all the promise that the Zend engine holds. Book Style and Organization T he book will emphasize clarity over conceptual profundity and practical real-world examples over abstract examples (such as "Hello World" and "$foobar = 1"). Our aim is to present code that is useful (with little modification) to the reader, not intricate technical discussions. These examples will try to be as web browser-neutral as possible, which is a good strategy for any robust web application. Use of TEAM FLY PRESENTS
  18. Simpo PDF Merge and Split Unregistered Version - p latform specific client browser features will be avoided, e.g. if JavaScript is generated, this will be constructed so it will work well independently of whether the user runs Internet Explorer under Windows or Netscape Navigator on a Solaris box. Although PHP development requires the use of other technologies such as HTML, SQL, and HTTP servers, this book will not attempt to be a full resource on those subject areas. Technologies other than PHP will be addressed only in the context of their use and interaction with PHP. For example, we will not discuss at length the basis of XML and its specification. We will, however, demonstrate how to use MySQL and PHP together to build a web database application. We divide this book into a number of sections. The first section introduces the basics of the language with clear and "real life" examples, that is we tried to avoid making "Hello World"-like scripts, after all you want to develop solutions for a web application. The second section will contain chapters showing more complex use of PHP functions (databases, image creation, etc.). The third section will deal with fully discussed applications (such as a shopping cart application). And finally we are including a section with appendices containing a general reference on the language, as well as discussions on the open source concept and similar topics. In Closing T his book will cover the core language of PHP, including issues such as installation and configuration, and demonstrations of the practical use of the language. The focus is on common business needs, such as database application development and e-commerce. Explicit mention will be made of the pros and cons of certain approaches, and the trade-offs involved. In the end, our aim is to provide you with a new and powerful tool, so that you, the web application developer, will be able to create a better project in a shorter period of time. If we at least convince you to consider PHP as a viable alternative for your projects, we will be happy. And even more, if you decide not only to think about using it, but actually go ahead and use it for real and then participate in the community of all the other PHP developers, that my friend will make us feel warm all over (as the saying goes). So, sit back, grab some coffee and enjoy. Useful Websites H ere is a preliminary list of websites you may like to visit to keep up-to-date with developments in PHP, Apache and MySQL. A fuller reference list is included in the appendices at the end of this book. P HP site: h ttp:// ❑ P HPBuilder site: h ttp:// ❑ A pache Project site: h ttp:// ❑ M ySQL site: h ttp:// ❑ TEAM FLY PRESENTS
  19. Simpo PDF Merge and Split Unregistered Version - 2 Installing and Configuring PHP I n this chapter we shall explore the ways and means to get us equipped with a working version of PHP. We will configure PHP so that it is able to utilize MySQL, which we will be using as our preferred choice of database product. We will also add two of the many extensions that PHP supports: Boutell's GD library (for image creation and manipulation) and Expat (for XML parser support). PHP comes with a myriad of options, both to build the distribution and also to configure an installation. PHP supports several APIs and interfaces to other programming tools. The sheer number of these tools is daunting, not to speak of the configuration possibilities for each of these. Before we get involved in the detail of installing PHP, it would be worthwhile to consider what we would expect to do with PHP in the near future. Depending on this we need to include only those particular modules that are germane to the kind of stuff we plan to do with the installation. The advantage with choosing only the modules that we need is obviously a smaller binary and the performance benefits associated with it. We could always load the less frequently used modules explicitly, but if we use this strategy with frequently used ones the installation mostly takes a performance hit. In the first section we shall take a look at the installation part with small digressions on common pitfalls while installing and how to circumvent them. In the latter section we shall look at configuring PHP to suit our expected usage pattern. During the course of this chapter we shall be looking at: P HP’s scope and dependency on other software. Why is this dependency there? ❑ G etting us to quickly installing a working version of PHP. We could then go on and change ❑ the configuration to suit our needs. V arious options in terms of platforms and configurations for installing PHP. ❑ E xploring the various mechanisms of configuring PHP – build-time settings, configuration ❑ files, etc. TEAM FLY PRESENTS
  20. Simpo PDF Merge and Split Unregistered Version - C onfiguration of PHP with respect to database options, mail options, security and a few ❑ general options. Installation P HP is supported on quite a few platforms, many of them UNIX-like and of course on Microsoft’s operating systems supporting the Win32 environment. Since PHP cannot do much without a web server, when we talk of installing PHP on a platform, we also need to take into consideration the web server that we plan to use. Platforms and Web Servers O n the UNIX front, Apache is the web server of choice for most installations. PHP is rated as the second most popular Apache module, where it is found to perform very well. PHP can be compiled as a standalone interpreter, like any other CGI scripting language or it can be compiled as an Apache module. Apache is also available on the Windows platform and PHP is supported for this combination. FHTTPd is an open source, UNIX-only web server for which PHP can be configured as a module. PHP distributions for Microsoft’s web server solutions IIS 3 up to IIS 5, PWS on Windows95/98 and NT are available. Omni HTTPd for Windows is another supported web server among others for which results may vary. There are a number of other web servers that can be used with PHP, like Xitami for instance, but it must also be remembered that Apache is the only web server for which PHP can be compiled as a module – the rest are CGI interpreter installations. PHP Modules P HP has support, by way of APIs and interfaces to a vast chest of tools and platforms. Most of these tools or a dd-on m odules are available as libraries (DLLs in Windows parlance). We shall see some common tools supported by PHP: A l arge number of databases are supported for connectivity by PHP. As of PHP 3, these ❑ include Adabas, dBase, Empress, FilePro, Informix, InterBase, mSQL, MySQL, Oracle, PostgreSQLQL, Solid, Sybase, Velocis and several flavors of the Unix dbm,. Any other database that supports ODBC (Open Database Connectivity) can be accessed using PHP’s ODBC support, e.g. IBM’s DB2 database. L DAP (Light-weight Directory Access Protocol) is another supported protocol. PHP provides ❑ APIs for writing LDAP client programs. LDAP is a protocol used to access directory related information such as address books, white pages etc. X ML (eXtended Markup Language) touted as the future language of the web is also ❑ supported. XML (among others) separates content or the information that a web page holds from the presentation of the page. WDDX (Web Distributed Data eXchange) a technology derived from XML is also supported. M ail protocols such as IMAP (Interactive Mail Access Protocol) and SMTP (Simple Mail ❑ Transport Protocol) are supported. IMAP is a protocol used for mail retrieval and SMTP is used for routing mail on the Internet. TEAM FLY PRESENTS



Đồng bộ tài khoản