Register your product to gain access to bonus material or receive a coupon.
This PDF will be accessible from your Account page after purchase and requires PDF reading software, such as Acrobat® Reader®.
The eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.
PHP & MySQL Web Development teaches the reader to develop dynamic, secure e-commerce Web sites and Web applications. The book shows how to integrate and implement these technologies by following real-world examples and working sample projects. It also covers the related technologies needed to build a commercial Web site such as SSL, shopping carts, and payment systems. The CD includes a Linux distribution, MySQL, PHP4 and utilities for the projects and code listings.
I. USING PHP.
PHP Crash Course.Using PHP. Sample Application: Bob's Auto Parts.
The Order Form. Processing the Form.
Embedding PHP in HTML.
Using PHP Tags. PHP Tag Styles. PHP Statements. Whitespace. Comments.
Adding Dynamic Content.
Calling Functions. The date() Function.
Accessing Form Variables.
Form Variables. String Concatenation. Variables and Literals.
Identifiers. User-Declared Variables. Assigning Values to Variables. Variable Types.
PHP's Data Types. Type Strength. Type Casting. Variable Variables.
Constants. Variable Scope. Operators.
Arithmetic Operators. String Operators. Assignment Operators. Comparison Operators. Logical Operators. Bitwise Operators. Other Operators.
Using Operators: Working Out the Form Totals. Precedence and Associativity: Evaluating Expressions. Variable Functions.
Testing and Setting Variable Types. Testing Variable Status. Reinterpreting Variables.
Control Structures. Making Decisions with Conditionals.
if Statements. Code Blocks. A Side Note: Indenting Your Code. else Statements. elseif Statements. switch Statements. Comparing the Different Conditionals.
Iteration: Repeating Actions.
while Loops. for Loops. do..while Loops.
Breaking Out of a Control Structure or Script. Next: Saving the Customer's Order.
2. Storing and Retrieving Data.Saving Data for Later. Storing and Retrieving Bob's Orders. Overview of File Processing. Opening a File.
File Modes. Using fopen() to Open a File. Opening Files for FTP or HTTP. Problems Opening Files.
Writing to a File. Parameters for fwrite(). File Formats.
Closing a File. Reading from a File.
Opening a File for Reading: fopen(). Knowing When to Stop: feof(). Reading a Line at a Time: fgets(), fgetss(), and fgetcsv(). Reading the Whole File: readfile(), fpassthru(), file(). Reading a Character: fgetc(). Reading an Arbitrary Length: fread().
Other Useful File Functions.
Checking Whether a File Is There: file_exists(). Knowing How Big a File Is: filesize(). Deleting a File: unlink(). Navigating Inside a File: rewind(), fseek(), and ftell().
File Locking. Doing It a Better Way: Database Management Systems.
Problems with Using Flat Files. How RDBMSs Solve These Problems. Further Reading. Next.
3. Using Arrays.What Is an Array? Numerically Indexed Arrays.
Initializing Numerically Indexed Arrays. Accessing Array Contents. Using Loops to Access the Array.
Associative Arrays. Initializing an Associative Array. Accessing the Array Elements. Using Loops with each() and list().
Multidimensional Arrays. Sorting Arrays.
Using sort(). Using asort() and ksort() to Sort Associative Arrays. Sorting in Reverse.
Sorting Multidimensional Arrays.
User Defined Sorts. Reverse User Sorts.
Reordering Arrays.
Using shuffle(). Using array_reverse().
Loading Arrays from Files. Other Array Manipulations.
Navigating Within an Array: each, current(), reset(), end(), next(), pos(), and prev(). Applying Any Function to Each Element in an Array: array_walk(). Counting Elements in an Array: count(), sizeof(), and array_count_values(). Converting Arrays to Scalar Variables: extract().
Further Reading. Next.
4. String Manipulation and Regular Expressions.Example Application: Smart Form Mail. Formatting Strings.
Trimming Strings: chop(), ltrim(), and trim(). Formatting Strings for Presentation. Formatting Strings for Storage: AddSlashes() and StripSlashes().
Joining and Splitting Strings with String Functions.
Using explode(), implode(), and join(). Using strtok(). Using substr().
Comparing Strings.
String Ordering: strcmp(),strcasecmp(), and strnatcmp(). Testing String Length with strlen().
Matching and Replacing Substrings with String Functions.
Finding Strings in Strings: strstr(), strchr(), strrchr(), stristr(). Finding the Position of a Substring: strpos(), strrpos(). Replacing Substrings: str_replace(), substr_replace().
Introduction to Regular Expressions.
The Basics. Character Sets and Classes. Repetition. Subexpressions. Counted Subexpressions. Anchoring to the Beginning or End of a String. Branching Matching Literal Special Characters. Summary of Special Characters. Putting It All Together for the Smart Form.
Finding Substrings with Regular Expressions. Replacing Substrings with Regular Expressions. Splitting Strings with Regular Expressions. Comparison of String Functions and Regular Expression Functions. Further Reading. Next.
5. Reusing Code and Writing Functions.Why Reuse Code?
Cost. Reliability. Consistency.
Using require() and include().
Using require(). File Name Extensions and Require(). PHP Tags and require().
Using require() for Web Site Templates.
Using auto_prepend_file and auto_append_file. Using include().
Using Functions in PHP.
Calling Functions. Call to Undefined Function. Case and Function Names.
Why Should You Define Your Own Functions? Basic Function Structure.
Naming Your Function.
Parameters. Scope. Pass by Reference Versus Pass by Value. Returning from Functions. Returning Values from Functions. Code Blocks.
Recursion. Further Reading. Next.
6. Object-Oriented PHP.Object-Oriented Concepts.
Classes and Objects. Polymorphism. Inheritance.
Creating Classes, Attributes, Operations in PHP. Structure of a Class. Constructors.
Instantiation. Using Class Attributes. Calling Class Operations. Implementing Inheritance in PHP.
Overriding. Multiple Inheritance.
Designing Classes. Writing the Code for Your Class. Next.
II. USING MYSQL.
7. Designing Your Web Database.Relational Database Concepts.
Tables. Columns. Rows. Values. Keys. Schemas. Relationships.
How to Design Your Web Database.
Think About the Real World Objects You Are Modeling. Avoid Storing Redundant Data. Use Atomic Column Values. Choose Sensible Keys. Think About the Questions You Want to Ask the Database. Avoid Designs with Many Empty Attributes. Summary of Table Types.
Web Database Architecture.
Architecture.
Further Reading. Next.
8. Creating Your Web Database.A Note on Using the MySQL Monitor. How to Log In to MySQL. Creating Databases and Users.
Creating the Database.
Users and Privileges. Introduction to MySQL's Privilege System.
Principle of Least Privilege. Setting Up Users: The GRANT Command. Types and Levels of Privilege. The REVOKE Command. Examples Using GRANT and REVOKE.
Setting Up a User for the Web.
Logging Out As root.
Using the Right Database. Creating Database Tables.
What the Other Keywords Mean. Understanding the Column Types. Looking at the Database with SHOW and DESCRIBE.
MySQL Identifiers. Column Data Types.
Numeric Types. Further Reading. Next.
9. Working with Your MySQL Database.What Is SQL? Inserting Data into the Database.
Retrieving Data from the Database. Retrieving Data with Specific Criteria. Retrieving Data from Multiple Tables. Retrieving Data in a Particular Order. Grouping and Aggregating Data. Choosing Which Rows to Return.
Updating Records in the Database. Altering Tables After Creation. Deleting Records from the Database. Dropping Tables. Dropping a Whole Database. Further Reading. Next.
10. Accessing Your MySQL Database from the Web with PHP.How Web Database Architectures Work. The Basic Steps in Querying a Database from the Web. Checking and Filtering Input Data. Setting Up a Connection. Choosing a Database to Use. Querying the Database. Retrieving the Query Results. Disconnecting from the Database. Putting New Information in the Database. Other Useful PHP-MySQL Functions.
Freeing Up Resources. Creating and Deleting Databases.
Other PHP-Database Interfaces. Further Reading. Next.
11. Advanced MySQL.Understanding the Privilege System in Detail.
The user Table. The db and host Tables. The tables_priv and columns_priv Tables. Access Control: How MySQL Uses the Grant Tables. Updating Privileges: When Do Changes Take Effect?
Making Your MySQL Database Secure.
MySQL from the Operating System's Point of View. Passwords. User Privileges. Web Issues.
Getting More Information About Databases.
Getting Information with SHOW. Getting Information About Columns with DESCRIBE. Understanding How Queries Work with EXPLAIN.
Speeding Up Queries with Indexes. General Optimization Tips.
Design Optimization. Permissions. Table Optimization. Using Indexes. Use Default Values. Use Persistent Connections. Other Tips.
Different Table Types. Loading Data from a File. Further Reading. Next.
III. E-COMMERCE AND SECURITY.
12. Running an E-commerce Site.What Do You Want to Achieve? Types of Commercial Web Sites.
Online Brochures. Taking Orders for Goods or Services. Providing Services and Digital Goods. Adding Value to Goods or Services. Cutting Costs.
Risks and Threats.
Crackers. Failing to Attract Sufficient Business. Computer Hardware Failure. Power, Communication, Network, or Shipping Failures. Extensive Competition. Software Errors. Evolving Governmental Policies and Taxes. System Capacity Limits.
Deciding on a Strategy. Next.
13. E-commerce Security Issues.How Important Is Your Information? Security Threats.
Exposure of Confidential Data. Loss or Destruction of Data. Modification of Data. Denial of Service. Errors in Software. Repudiation.
Balancing Usability, Performance, Cost, and Security. Creating a Security Policy. Authentication Principles. Using Authentication. Encryption Basics. Private Key Encryption. Public Key Encryption. Digital Signatures. Digital Certificates. Secure Web Servers. Auditing and Logging. Firewalls. Backing Up Data.
Backing Up General Files. Backing Up and Restoring Your MySQL Database.
Physical Security. Next.
14. Implementing Authentication with PHP and MySQL.Identifying Visitors. Implementing Access Control.
Storing Passwords. Encrypting Passwords. Protecting Multiple Pages.
Basic Authentication. Using Basic Authentication in PHP. Using Basic Authentication with Apache's .htaccess Files. Using Basic Authentication with IIS. Using mod_auth_mysql Authentication.
Installing mod_auth_mysql. Did It Work? Using mod_auth_mysql.
Creating Your Own Custom Authentication. Further Reading. Next.
15. Implementing Secure Transactions with PHP and MySQL.Providing Secure Transactions.
The User's Machine. The Internet. Your System.
Using Secure Sockets Layer (SSL). Screening User Input. Providing Secure Storage. Why Are You Storing Credit Card Numbers? Using Encryption in PHP. Further Reading. Next.
IV. ADVANCED PHP TECHNIQUES.
16. Interacting with the File System and the Server.Introduction to File Upload.
HTML for File Upload. Writing the PHP to Deal with the File. Common Problems.
Using Directory Functions.
Reading from Directories. Getting Info About the Current Directory. Creating and Deleting Directories.
Interacting with the File System.
Get File Info. Changing File Properties. Creating, Deleting, and Moving Files.
Using Program Execution Functions. Interacting with the Environment: getenv() and putenv(). Further Reading. Next.
17. Using Network and Protocol Functions.Overview of Protocols. Sending and Reading Email. Using Other Web Services. Using Network Lookup Functions. Using FTP.
Using FTP to Back Up or Mirror a File. Uploading Files. Avoiding Timeouts. Using Other FTP Functions.
Generic Network Communications with Curl. Further Reading. Next.
18. Managing the Date and Time.Getting the Date and Time from PHP.
Using the date() Function. Dealing with UNIX Time Stamps. Using the getdate() Function. Validating Dates.
Converting Between PHP and MySQL Date Formats. Date Calculations. Using the Calendar Functions. Further Reading. Next.
19. Generating Images.Setting Up Image Support in PHP. Image Formats.
JPEG. PNG. WBMP. GIF.
Creating Images.
Creating a Canvas Image. Drawing or Printing Text onto the Image. Outputting the Final Graphic. Cleaning Up.
Using Automatically Generated Images in Other Pages. Using Text and Fonts to Create Images.
Setting Up the Base Canvas. Fitting the Text onto the Button. Positioning the Text. Writing the Text onto the Button. Finishing Up.
Drawing Figures and Graphing Data. Other Image Functions. Further Reading. Next.
20. Using Session Control in PHP.What Session Control Is. Basic Session Functionality.
What Is a Cookie? Setting Cookies from PHP. Using Cookies with Sessions. Storing the Session ID.
Implementing Simple Sessions.
Starting a Session. Registering Session Variables. Using Session Variables. Deregistering Variables and Destroying the Session.
Simple Session Example. Configuring Session Control. Implementing Authentication with Session Control. Further Reading. Next.
21. Other Useful Features.Using Magic Quotes. Evaluating Strings: eval().Terminating Execution: die and exit. Serialization. Getting Information About the PHP Environment.
Finding Out What Extensions Are Loaded. Identifying the Script Owner. Finding Out When the Script Was Modified.
Loading Extensions Dynamically. Temporarily Altering the Runtime Environment. Source Highlighting. Next.
V. BUILDING PRACTICAL PHP AND MYSQL PROJECTS.
22. Using PHP and MySQL for Large Projects.Applying Software Engineering to Web Development. Planning and Running Web Application Project. Reusing Code. Writing Maintainable Code.
Coding Standards. Breaking Up Code. Using a Standard Directory Structure. Documenting and Sharing In-House Functions.
Implementing Version Control. Choosing a Development Environment. Documenting Your Projects. Prototyping. Separating Logic and Content. Optimizing Code.
Using Simple Optimizations. Using Zend Products.
Testing. Further Reading. Next.
23. Debugging.Programming Errors.
Syntax Errors. Runtime Errors. Logic Errors.
Variable Debugging Aid. Error Reporting Levels. Altering the Error Reporting Settings. Triggering Your Own Errors. Handling Errors Gracefully. Remote Debugging. Next.
24. Building User Authentication and Personalization.The Problem. Solution Components.
User Identification and Personalization. Storing Bookmarks. Recommending Bookmarks.
Solution Overview. Implementing the Database. Implementing the Basic Site. Implementing User Authentication.
Registering. Logging In. Logging Out. Changing Passwords. Resetting Forgotten Passwords.
Implementing Bookmark Storage and Retrieval.
Adding Bookmarks. Displaying Bookmarks. Deleting Bookmarks.
Implementing Recommendations. Wrapping Up and Possible Extensions. Next.
25. Building a Shopping Cart.The Problem. Solution Components.
Building an Online Catalog. Tracking a User's Purchases While She Shops. Payment. Administration Interface.
Solution Overview. Implementing the Database. Implementing the Online Catalog.
Listing Categories. Listing Books in a Category. Showing Book Details.
Implementing the Shopping Cart.
Using the show_cart.php Script. Viewing the Cart. Adding Items to the Cart. Saving the Updated Cart. Printing a Header Bar Summary. Checking Out.
Implementing Payment. Implementing an Administration Interface. Extending the Project. Using an Existing System. Next.
26. Building a Content Management System.The Problem. Solution Requirements. Editing Content.
Getting Content into the System. Databases Versus File Storage. Document Structure.
Using Metadata. Formatting the Output. Image Manipulation. Solution Design/Overview. Designing the Database. Implementation.
Front End. Back End. Searching. Editor Screen. Extending the Project.
27. Building a Web-Based Email Service.The Problem. Solution Components. Solution Overview. Setting Up the Database. Script Architecture. Logging In and Out. Setting Up Accounts.
Creating a New Account. Modifying an Existing Account. Deleting an Account.
Reading Mail.
Selecting an Account. Viewing Mailbox Contents. Reading a Mail Message. Viewing Message Headers. Deleting Mail.
Sending Mail.
Sending a New Message. Replying To or Forwarding Mail.
Extending the Project. Next.
28. Building a Mailing List Manager.The Problem. Solution Components.
Setting Up a Database of Lists and Subscribers.
File Upload. Sending Mail with Attachments. Solution Overview. Setting Up the Database. Script Architecture. Implementing Login.
Creating a New Account. Logging In.
Implementing User Functions.
Viewing Lists. Viewing List Information. Viewing List Archives. Subscribing and Unsubscribing. Changing Account Settings. Changing Passwords. Logging Out.
Implementing Administrative Functions.
Creating a New List. Uploading a New Newsletter. Handling Multiple File Upload. Previewing the Newsletter. Sending the Message. Extending the Project. Next.
29. Building Web Forums.The Problem. Solution Components. Solution Overview. Designing the Database. Viewing the Tree of Articles.
Expanding and Collapsing. Displaying the Articles. Using the treenode Class.
Viewing Individual Articles. Adding New Articles. Extensions. Using an Existing System. Next.
30. Generating Personalized Documents in Portable Format (PDF).The Problem. Evaluating Document Formats.
Paper. ASCII. HTML. Word Processor Formats. Rich Text Format. PostScript. Portable Document Format.
Solution Components.
Question and Answer System. Document Generation Software.
Solution Overview.
Asking the Questions. Grading the Answers. Generating an RTF Certificate. Generating a PDF Certificate from a Template. Generating a PDF Document Using PDFlib. A Hello World Script for PDFlib. Generating Our Certificate with PDFlib.
Problems with Headers. Extending the Project. Further Reading.
VI. APPENDIXES.
Appendix A. Installing PHP 4 and MySQL.Running PHP as a CGI Interpreter or Module. Installing Apache, PHP, and MySQL Under UNIX.
Apache and mod_SSL. httpd.conf File-Snippets. Is SSL Working?
Installing Apache, PHP, and MySQL Under Windows.
Installing MySQL Under Windows. Installing Apache Under Windows. Differences Between Apache for Windows and UNIX. Installing PHP for Windows. Installation Notes for Microsoft IIS. Installation Notes for Microsoft PWS.
Other Configurations.
Appendix B. Web Resources.PHP Resources. MySQL and SQL Specific Resources. Apache Resources. Web Development.
Index.