1. Trang chủ
  2. » Công Nghệ Thông Tin

FriendsofED.PHP.Solutions.Dynamic.Web.Design.Made.Easy

487 593 0
Tài liệu đã được kiểm tra trùng lặp

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 487
Dung lượng 8,9 MB

Nội dung

Friends of ED.PHP. Solutions php solutions dynamic web design made easy

CYAN MAGENTA YELLOW BLACK TH Powers In this book you’ll learn how to: ou want to make your websites more dynamic by adding a feedback form, creating a private area where members can upload images that are automatically resized, or perhaps storing all your content in a database The problem is, you’re not a programmer and the thought of writing code sends a chill up your spine Or maybe you’ve dabbled a bit in PHP and MySQL, but you can’t get past baby steps If this describes you, then you’ve just found the right book PHP and the MySQL database are deservedly the most popular combination for creating dynamic websites They’re free, easy to use, and provided by many web hosting companies in their standard packages Unfortunately, most PHP books either expect you to be an expert already or force you to go through endless exercises of little practical value In contrast, this book gives you real value right away through a series of practical examples that you can incorporate directly into your sites, optimizing performance and adding functionality such as file uploading, email feedback forms, image galleries, content management systems, and much more Each solution is created with not only functionality in mind, but also visual design But this book doesn’t just provide a collection of readymade scripts: each PHP Solution builds on what’s gone before, teaching you the basics of PHP and database design quickly and painlessly By the end of the book, you’ll have the confidence to start writing your own scripts or—if you prefer to leave that task to others— to adapt existing scripts to your own requirements Right from the start, you’re shown how easy it is to protect your sites by adopting secure coding practices The book has been written with an eye on forward and backward compatibility—recommending the latest PHP techniques, but providing alternative solutions for servers still running PHP 4.3 All database examples demonstrate how to use the original MySQL extension, MySQL Improved, or the PHP Data Objects (PDO) introduced in PHP 5.1, letting you choose the most suitable option for your setup Also Available S H E LV I N G C AT E G O R Y PHP PHP SOLUTIONS Create dynamic websites with design and usability in mind, as well as functionality Understand how PHP scripts work, giving you confidence to adapt them to your own needs Bring online forms to life, check required fields, and ensure user input is safe to process Upload files and automatically create thumbnails from larger images Manage website content with a searchable database Y MAE EASY STE WAY R P TO HP ! Create dynamic websites with PHP and MySQL, quickly and painlessly Learn practical techniques that you can use right away Keep hackers at bay with secure coding practices ISBN 1-59059-731-1 Mac/PC compatible 53499 US $34.99 DAVID POWERS www.friendsofed.com http://foundationphp.com 89253 59731 781590 597316 this print for reference only—size & color not accurate spine = 0.924" 488 page count 7311fm.qxd 10/20/06 10:46 AM Page i PHP Solutions: Dynamic Web Design Made Easy David Powers 7311fm.qxd 10/20/06 10:46 AM Page ii PHP Solutions: Dynamic Web Design Made Easy Copyright © 2006 by David Powers 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-59059-731-6 ISBN-10 (pbk): 1-59059-731-1 Printed and bound in the United States of America Trademarked names may appear in this book Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 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 contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710 Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit www.apress.com 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 freely available to readers at www.friendsofed.com in the Downloads section Credits Lead Editor Chris Mills Technical Reviewer Samuel Wright Senior Production Editor Laura Cheu Compositor Molly Sharp Editorial Board Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick, Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser, Keir Thomas, Matt Wade Artist April Milne Senior Project Manager Kylie Johnston Indexer John Collin Copy Edit Manager Nicole Flores Copy Editors Nicole Flores, Ami Knox Assistant Production Director Kari Brooks-Copony Proofreader Liz Welch Interior and Cover Designer Kurt Krames Manufacturing Director Tom Debolski Cover Photography David Powers 7311fm.qxd 10/20/06 10:46 AM Page iii C O N T E N T S AT A G L A N C E C O N T E N T S AT A G L A N C E About the Author About the Technical Reviewer About the Cover Image Intro xiv Chapter 1: What Is PHP—And Why Should I Care? Chapter 2: Getting Ready to Work with PHP Chapter 3: How to Write PHP Scripts Chapter 5: Bringing Forms to Life Chapter 6: Uploading Files xv xvii 15 45 Chapter 4: Lightening Your Workload with Includes 89 117 151 Chapter 7: Using PHP to Manage Files Chapter 8: Generating Thumbnail Images Chapter 9: Pages That Remember: Simple Login and Multipage Forms Chapter 11: Getting Started with a Database 211 233 261 285 Chapter 12: Creating a Dynamic Online Gallery Chapter 13: Managing Content 179 Chapter 10: Setting Up MySQL and phpMyAdmin 319 341 Chapter 14: Solutions to Common PHP/MySQL Problems 381 429 444 Chapter 15: Keeping Intruders at Bay Index xiii 7311fm.qxd 10/20/06 10:46 AM Page iv 7311fm.qxd 10/20/06 10:46 AM Page v CONTENTS About the Author About the Technical Reviewer About the Cover Image Intro xiii xiv xv xvii Chapter 1: What Is PHP—And Why Should I Care? Embracing the power of code Creating pages that think for themselves How hard is PHP to use and learn? Can I just copy and paste the code? How safe is PHP? 10 How to use this book 10 Using the download files 11 A note about versions 12 So, let’s get on with it 13 Chapter 2: Getting Ready to Work with PHP What you need to write and test PHP pages Checking whether your website supports PHP Choosing a good script editor for PHP Dreamweaver: Visual display of PHP output GoLive CS2: Some useful features EditPlus 2: Versatile text-only editor for Windows BBEdit and TextMate: Script editors for Mac OS X Checking your scripts with a file comparison utility Deciding where to test your pages What you need for a local test environment Individual programs or an all-in-one package? 15 16 16 17 17 18 19 19 19 20 20 21 7311fm.qxd 10/20/06 10:46 AM Page vi CONTENTS Setting up on Windows Getting Windows to display filename extensions Choosing a web server for Windows Installing Apache on Windows Starting and stopping Apache on Windows Setting up PHP on Windows Downloading and configuring PHP Adding PHP to your Windows startup procedure Configuring Apache to work with PHP Configuring IIS to work with PHP Testing PHP on Windows Troubleshooting Setting up on Mac OS X Using Apache on Mac OS X Starting and stopping Apache Where to locate your web files Installing PHP on Mac OS X Using a Mac package for PHP Configuring PHP to display errors on Mac OS X Testing PHP on Mac OS X Checking your PHP settings (Windows and Mac) What’s next? Chapter 3: How to Write PHP Scripts PHP: The big picture Telling the server to process PHP Embedding PHP in a web page Using variables to represent changing values Naming variables Assigning values to variables Ending commands with a semicolon Commenting scripts Single-line comments Multiline comments Using arrays to store multiple values PHP’s built-in superglobal arrays Understanding when to use quotes Special cases: true, false, and null Making decisions Making comparisons Using indenting and whitespace for clarity Using loops for repetitive tasks Using functions for preset tasks Displaying PHP output Joining strings together Working with numbers Understanding PHP error messages Now, on with the show vi 45 21 21 22 22 24 24 24 27 29 32 34 35 35 36 36 37 38 38 39 40 41 43 46 47 47 48 50 50 51 51 52 52 53 54 55 56 57 59 59 60 60 61 62 62 63 64 7311fm.qxd 10/20/06 10:46 AM Page vii CONTENTS PHP: A quick reference Using PHP in an existing website Data types in PHP Doing calculations with PHP Arithmetic operators Determining the order of calculations Combining calculations and assignment Adding to an existing string All you ever wanted to know about quotes—and more How PHP treats variables inside strings Using escape sequences inside double quotes Avoiding the need to escape quotes with heredoc syntax Unraveling the magic quotes tangle Creating arrays Using array() to build an indexed array Using array() to build an associative array Using array() to create an empty array Multidimensional arrays Using print_r() to inspect an array The truth according to PHP Explicit Boolean values Implicit Boolean values Making decisions by comparing two values Testing more than one condition Using the switch statement for decision chains Using the conditional operator Creating loops Loops using while and while The versatile for loop Looping through arrays with foreach Breaking out of a loop Modularizing code with functions Passing values to functions Returning values from functions Where to locate custom-built functions PHP quick checklist Chapter 4: Lightening Your Workload with Includes 64 64 64 66 66 67 68 68 68 69 70 70 71 73 74 74 74 75 75 76 76 77 77 78 79 80 80 81 81 82 83 83 84 85 85 85 89 Including code from other files 91 Introducing the PHP include commands 91 Choosing the right filename extension for includes 94 Using PHP to identify the current page 96 Creating pages with changing content 103 Preventing errors when an include file is missing 112 Choosing where to locate your include files 114 Security considerations with includes 115 Summary 115 vii 7311fm.qxd 10/20/06 10:46 AM Page viii CONTENTS Chapter 5: Bringing Forms to Life How PHP gathers information from a form Understanding the difference between post and get Keeping safe with PHP superglobals Sending email Removing unwanted backslashes from form input Processing and acknowledging the message Validating user input Making sure required fields aren’t blank Preserving user input when a form is incomplete Filtering out potential attacks Safely including the user’s address in email headers Handling multiple-choice form elements Redirecting to another page Summary Chapter 6: Uploading Files How PHP handles file uploads Checking whether your server supports uploads Adding a file upload field to a form Understanding the $_FILES array Establishing an upload directory Creating an upload folder for local testing Uploading files Moving the temporary file to the upload folder Removing spaces from filenames Rejecting large files Accepting only certain types of files Preventing files from being overwritten Organizing uploads into specific folders Uploading multiple files Points to watch with file uploads Chapter 7: Using PHP to Manage Files Checking that PHP has permission to open a file Configuration settings that affect file access Creating a file storage folder for local testing Reading and writing files Reading files in a single operation Opening and closing files for read/write operations Reading a file with fopen() Replacing content with fopen() Appending content with fopen() Writing a new file with fopen() Combined read/write operations with fopen() Moving the internal pointer viii 117 118 119 122 123 124 125 129 130 133 136 139 142 148 149 151 152 153 154 155 158 158 159 159 162 163 167 169 172 174 177 179 180 180 181 182 182 187 189 190 191 191 192 192 7311fm.qxd 10/20/06 10:46 AM Page ix CONTENTS Exploring the file system Inspecting a directory the quick way Opening a directory to inspect its contents Building a drop-down menu of files Automatically creating the next file in a series Opening remote data sources Creating a download link Summary Chapter 8: Generating Thumbnail Images Checking your server’s capabilities Manipulating images dynamically Making a smaller copy of an image Getting ready Building the script Resizing an image automatically on upload Further improvements Transferring your test files to a remote server Summary 195 195 196 197 200 203 207 209 211 Chapter 9: Pages That Remember: Simple Login and Multipage Forms What sessions are and how they work Creating PHP sessions Creating and destroying session variables Destroying a session The “Headers already sent” error Using sessions to restrict access Using file-based authentication Encrypting passwords Setting a time limit on sessions Passing information through multipage forms Coming up Chapter 10: Setting Up MySQL and phpMyAdmin Why MySQL? Which version? Installing MySQL on Windows Changing the default table type on Windows Essentials Starting and stopping MySQL manually on Windows Using the MySQL monitor on Windows Updating the PHP connector files Troubleshooting 212 213 214 214 215 223 228 230 230 233 234 236 236 237 237 238 241 247 253 256 258 261 262 263 263 268 268 269 270 271 ix

Ngày đăng: 09/01/2013, 09:45

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN