Beginning php and mysql from novice to professional 4th edition
lượt xem 22
download
Beginning PHP and MySQL: From Novice to Professional, Fourth Edition is a major update of W. Jason Gilmore's authoritative book on PHP and MySQL. The fourth edition includes complete coverage of PHP 5.3 features, including namespacing, an update of AMP stack installation and configuration, updates to Zend Framework, coverage of MySQL Workbench, and much more.
Bình luận(0) Đăng nhập để gửi bình luận!
Nội dung Text: Beginning php and mysql from novice to professional 4th edition
- CYAN YELLOW MAGENTA BLACK PANTONE 123 C www.it-ebooks.info BOOKS FOR PROFESSIONALS BY PROFESSIONALS ® THE EXPERT’S VOICE ® IN WEB DEVELOPMENT Companion eBook Available W. Jason Gilmore, Author of Beginning PHP and MySQL: Beginning PHP and Beginning PostgreSQL8, Beginning PHP From Novice to Professional and Oracle PHP and MySQL Beginning Dear Reader, PHP and MySQL have long ranked among the world's most popular technologies for building powerful web sites—and for good reason. Both offer developers an PHP and amazing array of features, yet have managed to remain very approachable even among the most novice developer. In the latest edition of this bestselling book, you'll learn all about PHP and MySQL, setting you along the path towards creat- ing the web site you've long dreamed about. I begin with a vast overview of PHP's capabilities, starting with in-depth instructions of the installation and configuration process. Next, I devote several chapters to fundamental PHP concepts, including variables, data types, func- tions, and object orientation. I also introduce key concepts such as HTML form processing, session handling, and AJAX. This new edition also introduces you to MySQL several of PHP's latest features, including namespaces, enhanced input filtering and validation, and improved configuration options. I then introduce many of MySQL's key features, beginning by guiding you through MySQL's installation and configuration process. Next, you'll learn about MySQL's storage engines and data types, administration utilities, and security fea- tures.. I'll also introduce you to several advanced features such as triggers, stored procedures, and views. Along the way, you'll gain insight into PHP's ability to com- municate with MySQL, and you’ll learn how to create and execute queries, perform searches, and carry out other key database tasks from within your web site. Whether you're a newcomer searching for a thorough introduction to these From Novice to Professional popular technologies or a seasoned developer in need of a comprehensive refer- ence, this book is for you. W. Jason Gilmore Learn how to build dynamic, database-driven web sites using Companion eBook two of the world’s most popular open source technologies THE APRESS ROADMAP PHP Objects, Pro PHP: Patterns, and Practice, Patterns, Frameworks, Third Edition Testing, and More PHP FOURTH EDITION for Absolute Beginners Pro PHP Object-Oriented FOURTH See last page for details PHP Refactoring Solutions on $10 eBook version EDITION Beginning PHP and MySQL, Practical Pro Fourth Edition Web 2.0 Applications PHP and jQuery with PHP W. Jason Gilmore Gilmore SOURCE CODE ONLINE www.apress.com ISBN 978-1-4302-3114-1 5 49 9 9 US $49.99 Shelve in: Web Development/PHP Programming 9 781430 231141 User level: Beginning/Intermediate this print for content only—size & color not accurate 7.5 x 9.25 spine = x.xxx" 824 page count
- www.it-ebooks.info
- www.it-ebooks.info Beginning PHP and MySQL From Novice to Professional Fourth Edition W. Jason Gilmore
- www.it-ebooks.info Beginning PHP and MySQL: From Novice to Professional, Fourth Edition Copyright © 2010 by W. Jason Gilmore All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302-3114-1 ISBN-13 (electronic): 978-1-4302-3115-8 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. President and Publisher: Paul Manning Lead Editor: Michelle Lowman Development Editor: Tom Welsh Technical Reviewer: Matt Wade Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editors: Anne Collett and Jennifer L. Blackwell Copy Editor: Mary Behr Compositor: Bytheway Publishing Services Indexer: BIM Indexing & Proofreading Services Artist: April Milne Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer- sbm.com, or visit www.springeronline.com. For information on translations, please e-mail rights@apress.com, or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/info/bulksales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at www.apress.com.
- www.it-ebooks.info CONTENTS AT A GLANCE Contents at a Glance About the Author................................................................................................ xxix About the Technical Reviewer ............................................................................ xxx Acknowledgments ............................................................................................. xxxi Introduction ...................................................................................................... xxxii Chapter 1: Introducing PHP ....................................................................................1 Chapter 2: Configuring Your Environment ..............................................................9 Chapter 3: PHP Basics ..........................................................................................41 Chapter 4: Functions.............................................................................................91 Chapter 5: Arrays................................................................................................103 Chapter 6: Object-Oriented PHP..........................................................................135 Chapter 7: Advanced OOP Features ....................................................................159 Chapter 8: Error and Exception Handling............................................................175 Chapter 9: Strings and Regular Expressions ......................................................191 Chapter 10: Working with the File and Operating System..................................229 Chapter 11: PEAR................................................................................................257 Chapter 12: Date and Time .................................................................................269 Chapter 13: Working with HTML Forms ..............................................................287 Chapter 14: Authenticating Your Users ..............................................................303 Chapter 15: Handling File Uploads......................................................................319 Chapter 16: Networking......................................................................................331 Chapter 17: PHP and LDAP..................................................................................351 iii
- www.it-ebooks.info CONTENTS AT A GLANCE Chapter 18: Session Handlers.............................................................................367 Chapter 19: Templating with Smarty..................................................................387 Chapter 20: Web Services...................................................................................411 Chapter 21: Securing Your Web Site...................................................................427 Chapter 22: Creating Ajax-enhanced Features with jQuery and PHP .................437 Chapter 23: Building Web Sites for the World ....................................................449 Chapter 24: Introducing the Zend Framework....................................................457 Chapter 25: Introducing MySQL ..........................................................................477 Chapter 26: Installing and Configuring MySQL ...................................................487 Chapter 27: The Many MySQL Clients .................................................................505 Chapter 28: MySQL Storage Engines and Data Types .........................................527 Chapter 29: Securing MySQL ..............................................................................557 Chapter 30: Using PHP with MySQL ....................................................................587 Chapter 31: Introducing PDO ..............................................................................607 Chapter 32: Stored Routines...............................................................................627 Chapter 33: MySQL Triggers ...............................................................................649 Chapter 34: MySQL Views...................................................................................659 Chapter 35: Practical Database Queries .............................................................673 Chapter 36: Indexes and Searching ....................................................................693 Chapter 37: Transactions....................................................................................709 Chapter 38: Importing and Exporting Data .........................................................719 Index ...................................................................................................................733 iv
- www.it-ebooks.info CONTENTS Contents About the Author................................................................................................ xxix About the Technical Reviewer ............................................................................ xxx Acknowledgments ............................................................................................. xxxi Introduction ...................................................................................................... xxxii Chapter 1: Introducing PHP ....................................................................................1 History ...............................................................................................................................1 PHP 4 ........................................................................................................................................................ 2 PHP 5 ........................................................................................................................................................ 3 PHP 5.3 ..................................................................................................................................................... 4 PHP 6 ........................................................................................................................................................ 5 General Language Features...............................................................................................5 Practicality................................................................................................................................................ 5 Power ....................................................................................................................................................... 6 Possibility ................................................................................................................................................. 7 Price ......................................................................................................................................................... 7 Summary ...........................................................................................................................8 Chapter 2: Configuring Your Environment ..............................................................9 Installation Prerequisites ...................................................................................................9 Downloading Apache.............................................................................................................................. 10 Downloading PHP ................................................................................................................................... 10 Downloading the Documentation ........................................................................................................... 11 Installing Apache and PHP on Linux ................................................................................12 v
- www.it-ebooks.info CONTENTS Installing Apache and PHP on Windows ..........................................................................13 Installing IIS and PHP on Windows ..................................................................................15 Testing Your Installation ..................................................................................................16 Configuring PHP...............................................................................................................18 Configuring PHP at Build Time on Linux ................................................................................................. 18 Customizing the Windows Build ............................................................................................................. 19 Run-Time Configuration...................................................................................................19 Managing PHP’s Configuration Directives .............................................................................................. 19 PHP’s Configuration Directives ............................................................................................................... 21 Choosing a Code Editor....................................................................................................37 Adobe Dreamweaver CS5....................................................................................................................... 37 Notepad++ ............................................................................................................................................. 37 PDT (PHP Development Tools) ................................................................................................................ 38 Zend Studio ............................................................................................................................................ 38 Choosing a Web Hosting Provider....................................................................................38 Seven Questions for Any Prospective Hosting Provider ......................................................................... 39 Summary .........................................................................................................................41 Chapter 3: PHP Basics ..........................................................................................41 Embedding PHP Code in Your Web Pages .......................................................................41 Default Syntax ........................................................................................................................................ 42 Short-Tags.............................................................................................................................................. 42 Script ...................................................................................................................................................... 43 ASP Style ................................................................................................................................................ 43 Embedding Multiple Code Blocks ........................................................................................................... 44 Commenting Your Code ...................................................................................................44 Single-Line C++ Syntax ......................................................................................................................... 44 Shell Syntax............................................................................................................................................ 44 Multiple-Line C Syntax ........................................................................................................................... 45 vi
- www.it-ebooks.info CONTENTS Outputting Data to the Browser .......................................................................................45 The print() Statement.............................................................................................................................. 46 The echo() Statement ............................................................................................................................. 47 The printf() Statement ............................................................................................................................ 47 The sprintf() Statement........................................................................................................................... 49 PHP’s Supported Data Types ...........................................................................................49 Scalar Data Types................................................................................................................................... 49 Compound Data Types............................................................................................................................ 51 Converting Between Data Types Using Type Casting ............................................................................. 52 Adapting Data Types with Type Juggling ............................................................................................... 53 Type-Related Functions.......................................................................................................................... 55 Type Identifier Functions ........................................................................................................................ 56 Identifiers.........................................................................................................................56 Variables ..........................................................................................................................57 Variable Declaration ............................................................................................................................... 58 Variable Scope........................................................................................................................................ 59 PHP’s Superglobal Variables .................................................................................................................. 62 Variable Variables................................................................................................................................... 68 Constants.........................................................................................................................68 Expressions .....................................................................................................................69 Operands ................................................................................................................................................ 69 Operators................................................................................................................................................ 69 String Interpolation ..........................................................................................................76 Double Quotes ........................................................................................................................................ 77 Escape Sequences ................................................................................................................................. 77 Single Quotes ......................................................................................................................................... 78 Curly Braces ........................................................................................................................................... 79 Heredoc .................................................................................................................................................. 79 vii
- www.it-ebooks.info CONTENTS Nowdoc................................................................................................................................................... 80 Control Structures............................................................................................................80 Conditional Statements .......................................................................................................................... 80 Looping Statements................................................................................................................................ 82 File-Inclusion Statements....................................................................................................................... 88 Summary .........................................................................................................................91 Chapter 4: Functions.............................................................................................91 Invoking a Function .........................................................................................................91 Creating a Function..........................................................................................................92 Passing Arguments by Value .................................................................................................................. 93 Passing Arguments by Reference........................................................................................................... 94 Default Argument Values........................................................................................................................ 94 Using Type Hinting.................................................................................................................................. 95 Returning Values from a Function .......................................................................................................... 96 Recursive Functions ............................................................................................................................... 97 Function Libraries..........................................................................................................100 Summary .......................................................................................................................101 Chapter 5: Arrays................................................................................................103 What Is an Array? ..........................................................................................................103 Creating an Array...........................................................................................................105 Creating Arrays with array() ................................................................................................................. 105 Extracting Arrays with list() .................................................................................................................. 106 Populating Arrays with a Predefined Value Range ............................................................................... 107 Testing for an Array .............................................................................................................................. 107 Outputting an Array........................................................................................................108 Printing Arrays for Testing Purposes.................................................................................................... 109 Adding and Removing Array Elements ..........................................................................110 Adding a Value to the Front of an Array................................................................................................ 110 viii
- www.it-ebooks.info CONTENTS Adding a Value to the End of an Array .................................................................................................. 110 Removing a Value from the Front of an Array ...................................................................................... 111 Removing a Value from the End of an Array......................................................................................... 111 Locating Array Elements................................................................................................111 Searching an Array ............................................................................................................................... 111 Retrieving Array Keys ........................................................................................................................... 113 Retrieving Array Values ........................................................................................................................ 113 Traversing Arrays...........................................................................................................113 Retrieving the Current Array Key .......................................................................................................... 114 Retrieving the Current Array Value ....................................................................................................... 114 Retrieving the Current Array Key and Value ......................................................................................... 115 Moving the Array Pointer ...................................................................................................................... 115 Passing Array Values to a Function ...................................................................................................... 116 Determining Array Size and Uniqueness .......................................................................117 Determining the Size of an Array.......................................................................................................... 117 Counting Array Value Frequency .......................................................................................................... 118 Determining Unique Array Values......................................................................................................... 119 Sorting Arrays................................................................................................................119 Reversing Array Element Order ............................................................................................................ 119 Flipping Array Keys and Values ............................................................................................................ 121 Sorting an Array.................................................................................................................................... 121 Merging, Slicing, Splicing, and Dissecting Arrays .........................................................126 Merging Arrays ..................................................................................................................................... 127 Recursively Appending Arrays.............................................................................................................. 127 Combining Two Arrays ......................................................................................................................... 128 Slicing an Array .................................................................................................................................... 128 Splicing an Array .................................................................................................................................. 129 Calculating an Array Intersection ......................................................................................................... 131 Calculating Associative Array Intersections ......................................................................................... 131 ix
- www.it-ebooks.info CONTENTS Calculating Array Differences . ............................................................................................................. 132 Calculating Associative Array Differences............................................................................................ 133 Other Useful Array Functions. ........................................................................................133 Returning a Random Set of Keys. ........................................................................................................ 133 Shuffling Array Elements. .................................................................................................................... 134 Summary . ......................................................................................................................135 Chapter 6: Object-Oriented PHP. .........................................................................135 The Benefits of OOP. ......................................................................................................135 Encapsulation . ..................................................................................................................................... 135 Inheritance. .......................................................................................................................................... 136 Polymorphism. ..................................................................................................................................... 136 Key OOP Concepts . ........................................................................................................137 Classes . ............................................................................................................................................... 137 Objects. ................................................................................................................................................ 138 Properties . ........................................................................................................................................... 138 Constants. ............................................................................................................................................ 144 Methods. .............................................................................................................................................. 145 Constructors and Destructors. .......................................................................................149 Constructors . ....................................................................................................................................... 149 Destructors . ......................................................................................................................................... 152 Static Class Members. ...................................................................................................153 The instanceof Keyword . ...............................................................................................154 Helper Functions. ...........................................................................................................154 Autoloading Objects. ......................................................................................................157 Summary . ......................................................................................................................157 Chapter 7: Advanced OOP Features . ...................................................................159 Advanced OOP Features Not Supported by PHP . ...........................................................159 x
- www.it-ebooks.info CONTENTS Object Cloning................................................................................................................160 Cloning Example................................................................................................................................... 160 The __clone() Method........................................................................................................................... 162 Inheritance.....................................................................................................................163 Class Inheritance .................................................................................................................................. 163 Inheritance and Constructors ............................................................................................................... 165 Inheritance and Late Static Binding ..................................................................................................... 167 Interfaces.......................................................................................................................168 Implementing a Single Interface .......................................................................................................... 169 Implementing Multiple Interfaces......................................................................................................... 170 Abstract Classes ............................................................................................................171 Introducing Namespaces ...............................................................................................172 Summary .......................................................................................................................174 Chapter 8: Error and Exception Handling............................................................175 Configuration Directives ................................................................................................175 Error Logging .................................................................................................................179 Exception Handling ........................................................................................................182 Why Exception Handling Is Handy ........................................................................................................ 182 PHP’s Exception-Handling Implementation .......................................................................................... 183 SPL’s Exceptions .................................................................................................................................. 189 Summary .......................................................................................................................191 Chapter 9: Strings and Regular Expressions ......................................................191 Regular Expressions ......................................................................................................191 Regular Expression Syntax (POSIX) ...................................................................................................... 192 PHP’s Regular Expression Functions (POSIX Extended) ....................................................................... 194 Regular Expression Syntax (Perl).......................................................................................................... 198 Other String-Specific Functions.....................................................................................205 xi
- www.it-ebooks.info CONTENTS Determining the Length of a String ...................................................................................................... 206 Comparing Two Strings ........................................................................................................................ 206 Manipulating String Case ..................................................................................................................... 209 Converting Strings to and from HTML .................................................................................................. 211 Alternatives for Regular Expression Functions ..............................................................216 Padding and Stripping a String............................................................................................................. 223 Counting Characters and Words........................................................................................................... 225 Taking Advantage of PEAR: Validate_US .......................................................................227 Installing Validate_US........................................................................................................................... 227 Using Validate_US ................................................................................................................................ 228 Summary .......................................................................................................................228 Chapter 10: Working with the File and Operating System..................................229 Learning About Files and Directories.............................................................................230 Parsing Directory Paths ........................................................................................................................ 230 Calculating File, Directory, and Disk Sizes ........................................................................................... 232 Determining Access and Modification Times ....................................................................................... 235 Working with Files .........................................................................................................236 The Concept of a Resource................................................................................................................... 237 Recognizing Newline Characters.......................................................................................................... 237 Recognizing the End-of-File Character................................................................................................. 237 Opening and Closing a File ................................................................................................................... 237 Reading from a File .............................................................................................................................. 239 Writing a String to a File....................................................................................................................... 246 Moving the File Pointer......................................................................................................................... 247 Reading Directory Contents.................................................................................................................. 247 Executing Shell Commands ...........................................................................................249 System-Level Program Execution..................................................................................251 Sanitizing the Input............................................................................................................................... 251 xii
- www.it-ebooks.info CONTENTS PHP’s Program Execution Functions .................................................................................................... 252 Summary .......................................................................................................................255 Chapter 11: PEAR................................................................................................257 The Power of PEAR: Converting Numeral Formats ........................................................257 Installing and Updating PEAR ........................................................................................258 Installing PEAR ..................................................................................................................................... 258 PEAR and Hosting Companies .............................................................................................................. 260 Updating PEAR...................................................................................................................................... 260 Using the PEAR Package Manager ................................................................................260 Viewing an Installed PEAR Package ..................................................................................................... 261 Learning More about an Installed PEAR Package................................................................................. 261 Installing a PEAR Package.................................................................................................................... 262 Including a Package within Your Scripts .............................................................................................. 264 Upgrading Packages............................................................................................................................. 264 Uninstalling a Package ......................................................................................................................... 265 Downgrading a Package....................................................................................................................... 266 Introducing Pyrus...........................................................................................................266 Installing Pyrus ..................................................................................................................................... 266 Summary .......................................................................................................................267 Chapter 12: Date and Time .................................................................................269 The Unix Timestamp ......................................................................................................269 PHP’s Date and Time Library .........................................................................................270 Validating Dates.................................................................................................................................... 270 Formatting Dates and Times ................................................................................................................ 271 Converting a Timestamp to User-Friendly Values ................................................................................ 275 Working with Timestamps.................................................................................................................... 276 Date Fu ..........................................................................................................................277 Displaying the Localized Date and Time............................................................................................... 277 xiii
- www.it-ebooks.info CONTENTS Displaying the Web Page’s Most Recent Modification Date ................................................................. 282 Determining the Number of Days in the Current Month ....................................................................... 282 Determining the Number of Days in Any Given Month ......................................................................... 282 Calculating the Date X Days from the Present Date ............................................................................. 283 Date and Time Enhancements for PHP 5.1+ Users .......................................................283 Introducing the DateTime Constructor.................................................................................................. 284 Formatting Dates .................................................................................................................................. 284 Setting the Date After Instantiation ...................................................................................................... 284 Setting the Time After Instantiation...................................................................................................... 285 Modifying Dates and Times .................................................................................................................. 285 Calculating the Difference between Two Dates ................................................................................... 286 Summary .......................................................................................................................286 Chapter 13: Working with HTML Forms ..............................................................287 PHP and Web Forms ......................................................................................................287 A Simple Example................................................................................................................................. 288 Validating Form Data .....................................................................................................289 File Deletion.......................................................................................................................................... 289 Cross-Site Scripting.............................................................................................................................. 290 Sanitizing User Input ............................................................................................................................ 291 Validating and Sanitizing Data with the Filter Extension ...................................................................... 294 Working with Multivalued Form Components....................................................................................... 296 Taking Advantage of PEAR: HTML_QuickForm2 ............................................................297 Installing HTML_QuickForm2 ............................................................................................................... 298 Creating and Validating a Simple Form ................................................................................................ 298 Summary .......................................................................................................................301 Chapter 14: Authenticating Your Users ..............................................................303 HTTP Authentication Concepts ......................................................................................303 Using Apache’s .htaccess Feature ....................................................................................................... 304 xiv
- www.it-ebooks.info CONTENTS Authenticating Your Users with PHP..............................................................................305 PHP’s Authentication Variables ............................................................................................................ 305 Useful Functions................................................................................................................................... 306 Hard-Coded Authentication .................................................................................................................. 307 File-Based Authentication .................................................................................................................... 308 Database-Based Authentication ........................................................................................................... 309 Taking Advantage of PEAR: Auth_HTTP................................................................................................ 311 User Login Administration .............................................................................................313 Testing Password Guessability with the CrackLib Library.................................................................... 313 One-Time URLs and Password Recovery.............................................................................................. 315 Summary .......................................................................................................................318 Chapter 15: Handling File Uploads......................................................................319 Uploading Files via HTTP ...............................................................................................319 Uploading Files with PHP...............................................................................................320 PHP’s File Upload/Resource Directives ................................................................................................ 320 The $_FILES Array ................................................................................................................................ 322 PHP’s File-Upload Functions ................................................................................................................ 322 Upload Error Messages ........................................................................................................................ 324 A Simple Example................................................................................................................................. 325 Taking Advantage of PEAR: HTTP_Upload .....................................................................326 Installing HTTP_Upload......................................................................................................................... 326 Uploading a File.................................................................................................................................... 326 Learning More About an Uploaded File................................................................................................. 327 Uploading Multiple Files ....................................................................................................................... 328 Summary .......................................................................................................................329 Chapter 16: Networking......................................................................................331 DNS, Services, and Servers ...........................................................................................331 DNS....................................................................................................................................................... 332 xv
- www.it-ebooks.info CONTENTS Services................................................................................................................................................ 336 Establishing Socket Connections ......................................................................................................... 337 Mail................................................................................................................................339 Configuration Directives ....................................................................................................................... 339 Sending E-mail Using a PHP Script ...................................................................................................... 340 Common Networking Tasks...........................................................................................344 Pinging a Server ................................................................................................................................... 345 Creating a Port Scanner ....................................................................................................................... 345 Creating a Subnet Converter ................................................................................................................ 346 Testing User Bandwidth ....................................................................................................................... 348 Summary .......................................................................................................................349 Chapter 17: PHP and LDAP..................................................................................351 Using LDAP from PHP ....................................................................................................352 Configuring LDAP for PHP..................................................................................................................... 352 Connecting to an LDAP Server.............................................................................................................. 352 Retrieving LDAP Data............................................................................................................................ 355 Counting Retrieved Entries ................................................................................................................... 358 Sorting LDAP Records........................................................................................................................... 359 Inserting LDAP Data.............................................................................................................................. 360 Updating LDAP Data.............................................................................................................................. 361 Deleting LDAP Data............................................................................................................................... 362 Working with the Distinguished Name ................................................................................................. 363 Error Handling....................................................................................................................................... 364 Summary .......................................................................................................................365 Chapter 18: Session Handlers.............................................................................367 What Is Session Handling? ............................................................................................367 The Session-Handling Process............................................................................................................. 368 Configuration Directives ................................................................................................369 xvi
- www.it-ebooks.info CONTENTS Managing the Session Storage Media.................................................................................................. 369 Setting the Session Files Path.............................................................................................................. 369 Automatically Enabling Sessions.......................................................................................................... 370 Setting the Session Name .................................................................................................................... 370 Choosing Cookies or URL Rewriting ..................................................................................................... 370 Automating URL Rewriting ................................................................................................................... 370 Setting the Session Cookie Lifetime..................................................................................................... 370 Setting the Session Cookie’s Valid URL Path........................................................................................ 371 Setting Caching Directions for Session-Enabled Pages ....................................................................... 371 Working with Sessions ..................................................................................................373 Starting a Session ................................................................................................................................ 373 Destroying a Session ............................................................................................................................ 373 Setting and Retrieving the Session ID .................................................................................................. 374 Creating and Deleting Session Variables.............................................................................................. 374 Encoding and Decoding Session Data .................................................................................................. 375 Practical Session-Handling Examples ...........................................................................377 Automatically Logging In Returning Users ........................................................................................... 378 Generating a Recently Viewed Document Index................................................................................... 379 Creating Custom Session Handlers ...............................................................................381 Tying Custom Session Functions into PHP’s Logic............................................................................... 382 Using Custom MySQL-Based Session Handlers ................................................................................... 382 Summary .......................................................................................................................385 Chapter 19: Templating with Smarty..................................................................387 What’s a Templating Engine? ........................................................................................387 Introducing Smarty ........................................................................................................389 Installing Smarty............................................................................................................390 Using Smarty .................................................................................................................391 Smarty’s Presentational Logic .......................................................................................393 xvii
- www.it-ebooks.info CONTENTS Comments ............................................................................................................................................ 394 Variable Modifiers................................................................................................................................. 394 Control Structures ................................................................................................................................ 397 Statements ........................................................................................................................................... 401 Creating Configuration Files ..........................................................................................404 config_load........................................................................................................................................... 404 Referencing Configuration Variables .................................................................................................... 405 Using CSS in Conjunction with Smarty ..........................................................................405 Caching..........................................................................................................................406 Working with the Cache Lifetime ......................................................................................................... 407 Eliminating Processing Overhead with isCached() ............................................................................... 407 Creating Multiple Caches per Template ............................................................................................... 408 Some Final Words About Caching ........................................................................................................ 409 Summary .......................................................................................................................409 Chapter 20: Web Services...................................................................................411 Why Web Services? .......................................................................................................411 Really Simple Syndication .............................................................................................413 Understanding RSS Syntax................................................................................................................... 414 Introducing SimplePie....................................................................................................416 Installing SimplePie .............................................................................................................................. 416 Parsing a Feed with SimplePie............................................................................................................. 417 Parsing Multiple Feeds ......................................................................................................................... 418 SimpleXML.....................................................................................................................419 Loading XML......................................................................................................................................... 420 Parsing XML.......................................................................................................................................... 421 Summary .......................................................................................................................425 Chapter 21: Securing Your Web Site...................................................................427 Configuring PHP Securely..............................................................................................428 xviii
CÓ THỂ BẠN MUỐN DOWNLOAD
-
PHP and MySQL
0 p | 174 | 68
-
WeB DeVelopmenT Introduces Introduces Beginning PHP and MySQL From
0 p | 195 | 37
-
Beginning PHP and MySQL E-Commerce, 2nd Edition
737 p | 99 | 27
-
Beginning PHP và MySQL 5 .
953 p | 227 | 18
-
Beginning PHP and MySQL E-Commerce From Novice to Professional phần 1
74 p | 106 | 14
-
Beginning PHP and MySQL
50 p | 102 | 11
-
Beginning PHP and MySQL E-Commerce From Novice to Professional phần 2
74 p | 62 | 8
-
Beginning PHP and MySQL E-Commerce From Novice to Professional phần 4
74 p | 70 | 8
-
Ebook Beginning PHP and MySQL: From novice to professional (3/e) - Part 1
538 p | 46 | 7
-
Beginning PHP and MySQL E-Commerce From Novice to Professional phần 3
74 p | 39 | 7
-
Ebook Beginning PHP and MySQL: From novice to professional (3/e) - Part 2
542 p | 42 | 7
-
Beginning PHP and MySQL E-Commerce From Novice to Professional phần 6
74 p | 51 | 5
-
Beginning PHP and MySQL E-Commerce From Novice to Professional phần 5
74 p | 50 | 4
-
Beginning PHP and MySQL E-Commerce From Novice to Professional phần 9
74 p | 53 | 4
-
Beginning PHP and MySQL From Novice to Professional phần 9
108 p | 50 | 1
-
Beginning PHP and MySQL From Novice to Professional phần 8
108 p | 62 | 1
-
Beginning PHP and MySQL From Novice to Professional phần 7
108 p | 53 | 1
Chịu trách nhiệm nội dung:
Nguyễn Công Hà - Giám đốc Công ty TNHH TÀI LIỆU TRỰC TUYẾN VI NA
LIÊN HỆ
Địa chỉ: P402, 54A Nơ Trang Long, Phường 14, Q.Bình Thạnh, TP.HCM
Hotline: 093 303 0098
Email: support@tailieu.vn