ebook img

Apress - PHP for Absolute Beginners (2009). - Index of PDF

410 Pages·2009·9.59 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Apress - PHP for Absolute Beginners (2009). - Index of

Cyan yelloW MaGenTa BlaCk Books for professionals By professionals® The experT’s VoiCe® in open sourCe Companion eBook Available PHP for Absolute Beginners P Dear Reader, H PHP for Absolute Beginners will take you from zero to full-speed with PHP pro- gramming in an easy-to-understand, practical manner. Rather than building applications with no real-world use, this book teaches you PHP by walking you P through the development of a blogging web site. PHP You’ll start by creating a simple web-ready blog, then you'll learn how to add password-protected controls, support for multiple pages, the ability to upload f and resize images, a user comment system, and finally, how to integrate with o sites like Twitter. Along the way, you'll also learn a few advanced tricks including creating r friendly URLs with .htaccess, using regular expressions, object-oriented pro- A gramming, and more. I wrote this book to help you make the leap to PHP developer in hopes that b you can put your valuable skills to work for your company, your clients, or on your own personal blog. The concepts in this book will leave you ready to take s on the challenges of the new online world, all while having fun! o Jason Lengstorf l for Absolute Beginners u t THE APRESS ROADMAP e Pro PHP: PHP for PHP Objects, Patterns, Patterns, Frameworks, B Absolute Beginners and Practice Testing, and More e Beginning PHP Practical Web 2.0 and MySQL Applications with PHP g i Beginning Ajax and PHP n Everything you need to know to Companion eBook n get started with PHP e r See last page for details s on $10 eBook version L e Jason Lengstorf SOURCE CODE ONLINE n www.apress.com (cid:41)(cid:51)(cid:34)(cid:46)(cid:0)(cid:25)(cid:23)(cid:24)(cid:13)(cid:17)(cid:13)(cid:20)(cid:19)(cid:16)(cid:18)(cid:13)(cid:18)(cid:20)(cid:23)(cid:19)(cid:13)(cid:16) g s (cid:21)(cid:19)(cid:20)(cid:25)(cid:25) t o r US $34.99 f Shelve in: PHP User level: (cid:25) (cid:23)(cid:24)(cid:17)(cid:20)(cid:19)(cid:16) (cid:18)(cid:18)(cid:20)(cid:23)(cid:19)(cid:16) Beginner this print for content only—size & color not accurate trim = 7.5" x 9.25" spine = 0.75" 408 page count Download at WoweBook.Com PHP for Absolute Beginners ■ ■ ■ Jason Lengstorf i Download at WoweBook.Com PHP for Absolute Beginners Copyright © 2009 by Jason Lengstorf 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-2473-0 ISBN-13 (electronic): 978-1-4302-2474-7 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 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. Lead Editor: Michelle Lowman Technical Reviewer: Gordon Forsythe Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Michelle Lowman, Matthew Moodie, Jeffrey Pepper, Frank Pohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Project Manager: Debra Kelly Copy Editor: Patrick Meader Compositor: Lynn L’Heureux Indexer: John Collin 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 [email protected], or visit http://www.springeronline.com. For information on translations, please e-mail [email protected], or visit http://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 http://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 http://www.apress.com. You will need to answer questions pertaining to this book in order to successfully download the code. ii Download at WoweBook.Com For my dad, who showed me that nothing stands between a bear and its honey. iii Download at WoweBook.Com Contents at a Glance ■ About the Author.......................................................................................................xiv ■ About the Technical Reviewer....................................................................................xv ■ Acknowledgments.....................................................................................................xvi ■ Introduction..............................................................................................................xvii ■ Chapter 1: Setting Up the PHP Development Environment...........................................3 ■ Chapter 2: Understanding PHP: Language Basics......................................................29 ■ Chapter 3: Passing Information with PHP..................................................................69 ■ Chapter 4: Working with Databases...........................................................................97 ■ Chapter 5: Building the Entry Manager....................................................................125 ■ Chapter 6: Adding Support for Multiple Pages.........................................................157 ■ Chapter 7: Updating and Deleting Entries................................................................187 ■ Chapter 8: Adding the Ability to Upload Images......................................................207 ■ Chapter 9: Syndicating the Blog...............................................................................263 ■ Chapter 10: Adding a Commenting System to Your Blog........................................283 ■ Chapter 11: Adding Password Protection to Administrative Links..........................311 ■ Chapter 12: Finishing Touches.................................................................................341 ■ Index .......................................................................................................................369 iv Download at WoweBook.Com Contents ■ About the Author.......................................................................................................xiv ■ About the Technical Reviewer....................................................................................xv ■ Acknowledgments.....................................................................................................xvi ■ Introduction..............................................................................................................xvii ■ Chapter 1: Setting Up the PHP Development Environment...........................................3 Why You Need Apache, MySQL, and PHP................................................................................3 Drilling Down on PHP........................................................................................................3 Stable/Production vs. Development Releases............................................................4 How PHP Works..........................................................................................................4 Server-Side vs. Client-Side Scripting.........................................................................4 What Apache Does......................................................................................................5 Store Info with MySQL......................................................................................................5 Installing PHP, Apache, and MySQL (the Hard Way)................................................................6 Installation Made Easy......................................................................................................6 Installing XAMPP...............................................................................................................6 Step 1: Download XAMPP...........................................................................................7 Step 2: Open the Installer and Follow the Instructions...............................................7 Step 3: Test XAMPP to Ensure Proper Installation....................................................11 Choosing a Development Kit.................................................................................................15 Benefiting from SDKs and IDEs.......................................................................................15 Choosing the Right SDK..................................................................................................18 The Eclipse Foundation and PDT..............................................................................18 Installing and Using the Eclipse PDT.....................................................................................18 Step 1: Downloading the PDT.........................................................................................19 Step 2: Unpacking the PDT Archive................................................................................19 Step 3: Choosing Your Project Workspace.....................................................................20 Step 4: Creating Your First Project.................................................................................23 v Download at WoweBook.Com ■ CONTENTS Step 5: Creating a File....................................................................................................26 Step 6: Writing Your First Script.....................................................................................27 Summary...............................................................................................................................28 ■ Chapter 2: Understanding PHP: Language Basics......................................................29 Embedding PHP Scripts.........................................................................................................29 Alternative Delimiters.....................................................................................................30 Short Tags................................................................................................................31 HTML <script> Tags and ASP-Style Delimiters........................................................31 Variables and Datatypes........................................................................................................32 What Is a Variable?.........................................................................................................32 Storing Values in a Variable............................................................................................32 Understanding Strings..............................................................................................33 Understanding Integers............................................................................................37 Understanding Floating Point Numbers....................................................................37 Understanding Boolean Values.................................................................................37 Understanding Arrays...............................................................................................38 Sending Data to the Browser as Output................................................................................41 The Different Output Commands....................................................................................41 The print() Statement................................................................................................41 The echo() Statement...............................................................................................42 The printf() Statement...............................................................................................43 The sprintf() Statement.............................................................................................45 Commenting Your Code.........................................................................................................46 Inline vs. Block Comments.............................................................................................46 Other Comment Styles....................................................................................................47 Operators...............................................................................................................................47 Arithmetic Operators......................................................................................................48 Arithmetic Assignment Operators...................................................................................48 Comparison Operators....................................................................................................50 Error Control Operators...................................................................................................51 Incrementing/Decrementing Operators..........................................................................52 Logical Operators............................................................................................................52 String Operators.............................................................................................................54 Control Structures.................................................................................................................54 vi Download at WoweBook.Com ■ CONTENTS if, else, and else if..........................................................................................................55 while and do-while.........................................................................................................56 for 58 foreach............................................................................................................................59 break...............................................................................................................................60 switch.............................................................................................................................61 continue..........................................................................................................................62 return..............................................................................................................................63 include, include_once, require, and require_once.........................................................63 goto.................................................................................................................................65 User-Defined.........................................................................................................................66 Returning Values from Functions.............................................................................67 Summary...............................................................................................................................68 ■ Chapter 3: Passing Information with PHP..................................................................69 Superglobal Arrays................................................................................................................69 Variable Scope................................................................................................................70 $GLOBALS.......................................................................................................................73 $_SERVER.......................................................................................................................74 $_GET.............................................................................................................................77 URL Encoding............................................................................................................78 Accessing URL Variables..........................................................................................78 $_POST...........................................................................................................................82 $_REQUEST.....................................................................................................................84 $_FILES...........................................................................................................................85 $_SESSION.....................................................................................................................89 Using session_destroy()............................................................................................92 $_COOKIE........................................................................................................................93 Summary...............................................................................................................................95 ■ Chapter 4: Working with Databases...........................................................................97 The Basics of MySQL Data Storage.......................................................................................97 Manipulating Data in MySQL Tables......................................................................................98 Creating and Deleting Databases...................................................................................99 Deleting Databases Using DROP...............................................................................99 Creating Databases Using CREATE.........................................................................100 vii Download at WoweBook.Com ■ CONTENTS The CREATE TABLE Statement......................................................................................100 Data Types in MySQL..............................................................................................102 Understanding PRIMARY KEY..................................................................................102 Understanding AUTO_INCREMENT..........................................................................102 Indexes in MySQL...................................................................................................103 The INSERT Statement..................................................................................................103 The SELECT Statement.................................................................................................105 The UPDATE Statement.................................................................................................107 The JOIN Statement......................................................................................................108 The DELETE Statement.................................................................................................109 Opening a Connection.........................................................................................................109 PHP’s MySQL Extension................................................................................................109 The MySQLi Extension..................................................................................................111 Using Prepared Statements....................................................................................111 Using MySQLi..........................................................................................................112 Using Prepared Statements with MySQLi...............................................................113 PHP Data Objects (PDO)................................................................................................116 Rewriting Your Example in PDO..............................................................................116 Table Structure and a Crash Course in Planning.................................................................118 Planning Database Tables............................................................................................118 The Shortcut Selector (*).............................................................................................122 Summary.............................................................................................................................122 Recommended Reading................................................................................................122 ■ Chapter 5: Building the Entry Manager....................................................................125 Planning the Entry Database Table.....................................................................................125 Creating the Entry Input Form.............................................................................................128 Create a Script to Process the Form Input..........................................................................132 Performing the Initial Verification.................................................................................133 Connect to the Database..............................................................................................134 Keeping Database Credentials Separate................................................................134 Connecting to the Database in update.inc.php.......................................................135 Save the Entry to the Database....................................................................................135 Retrieve the Entry’s Unique ID and Display the Entry to the User.................................136 Displaying the Saved Entries...............................................................................................138 viii Download at WoweBook.Com

Description:
Available. THE EXPERTLS VOICE® IN OPEN SOURCE. PHP for Absolute Beginners. Jason Lengstorf. Everything you need to know to get started with PHP .
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.