100% found this document useful (6 votes)
51 views

Download Core web application development with PHP and MySQL 1. printing Edition Wandschneider ebook All Chapters PDF

Core

Uploaded by

komanramahbm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (6 votes)
51 views

Download Core web application development with PHP and MySQL 1. printing Edition Wandschneider ebook All Chapters PDF

Core

Uploaded by

komanramahbm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Download the full version of the ebook at

https://ebookfinal.com

Core web application development with PHP and


MySQL 1. printing Edition Wandschneider

https://ebookfinal.com/download/core-web-
application-development-with-php-and-
mysql-1-printing-edition-wandschneider/

Explore and download more ebook at https://ebookfinal.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

PHP and MySQL Web development fourth edition Thomson

https://ebookfinal.com/download/php-and-mysql-web-development-fourth-
edition-thomson/

ebookfinal.com

PHP and MySQL Web Development Second Edition Welling L.

https://ebookfinal.com/download/php-and-mysql-web-development-second-
edition-welling-l/

ebookfinal.com

Web Application Development with Yii and PHP 2nd Revised


ed. Edition Jeffrey Winesett

https://ebookfinal.com/download/web-application-development-with-yii-
and-php-2nd-revised-ed-edition-jeffrey-winesett/

ebookfinal.com

Build Your Own Database Driven Web Site Using PHP MySQL
4th Edition Kevin Yank

https://ebookfinal.com/download/build-your-own-database-driven-web-
site-using-php-mysql-4th-edition-kevin-yank/

ebookfinal.com
Learning PHP MySQL JavaScript and CSS 2nd Edition Robin
Nixon

https://ebookfinal.com/download/learning-php-mysql-javascript-and-
css-2nd-edition-robin-nixon/

ebookfinal.com

Learning PHP MySQL Step by Step Guide to Creating Database


Driven Web Sites Second Edition Michele E. Davis

https://ebookfinal.com/download/learning-php-mysql-step-by-step-guide-
to-creating-database-driven-web-sites-second-edition-michele-e-davis/

ebookfinal.com

Learning PHP MySQL JavaScript With jQuery CSS HTML5 Early


Release 5th 5th Edition Robin Nixon

https://ebookfinal.com/download/learning-php-mysql-javascript-with-
jquery-css-html5-early-release-5th-5th-edition-robin-nixon/

ebookfinal.com

PHP MySQL The Missing Manual Second Edition Brett


Mclaughlin

https://ebookfinal.com/download/php-mysql-the-missing-manual-second-
edition-brett-mclaughlin/

ebookfinal.com

Learning Joomla 1 5 Extension Development Creating Modules


Components and Plugins with PHP 1st Edition Joseph L.
Leblanc
https://ebookfinal.com/download/learning-joomla-1-5-extension-
development-creating-modules-components-and-plugins-with-php-1st-
edition-joseph-l-leblanc/
ebookfinal.com
Core web application development with PHP and
MySQL 1. printing Edition Wandschneider Digital
Instant Download
Author(s): Wandschneider, Marc
ISBN(s): 9780131867161, 0131867164
Edition: 1. printing
File Details: PDF, 9.63 MB
Year: 2005
Language: english
core
WEB APPLICATION
DEVELOPMENT
WITH PHP AND
MYSQL
core
WEB APPLICATION
DEVELOPMENT
WITH PHP AND
MYSQL

MARC WANDSCHNEIDER

Prentice Hall Professional Technical Reference

Upper Saddle River, NJ • Boston• Indianapolis • San Francisco

New York • Toronto • Montreal • London • Munich • Paris • Madrid

Capetown • Sydney • Tokyo • Singapore • Mexico City


Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in this book, and the publisher was aware
of a trademark claim, the designations have been printed with initial capital letters or in all capitals.
The author and publisher have taken care in the preparation of this book, but make no expressed or
implied warranty of any kind and assume no responsibility for errors or omissions. No liability is
assumed for incidental or consequential damages in connection with or arising out of the use of the
information or programs contained herein.
The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or
special sales, which may include electronic versions and/or custom covers and content particular to
your business, training goals, marketing focus, and branding interests. For more information, please
contact:
U. S. Corporate and Government Sales
(800) 382-3419
[email protected]
For sales outside the U. S., please contact:
International Sales
[email protected]

This Book Is Safari Enabled


The Safari Enabled icon on the cover of your favorite technology book means the
book is available through Safari Bookshelf. When you buy this book, you get free
access to the online edition for 45 days. Safari Bookshelf is an electronic reference
library that lets you easily search thousands of technical books, find code samples, download chap-
ters, and access technical information whenever and wherever you need it.
To gain 45-day Safari Enabled access to this book:
Go to http://www.phptr.com/safarienabled
Complete the brief registration form
Enter the coupon code [SE coupon code to come]
If you have difficulty registering on Safari Bookshelf or accessing the online edition, please e-mail
[email protected].

Visit us on the Web: www.phptr.com


Library of Congress Cataloging-in-Publication Data:
Wandschneider, Marc
Core Web application development with PHP and MySQL / Marc Wanddschneider.
p. cm.
Includes index.
ISBN 0-13-186716-4
1. Web site development. 2. PHP (Computer program language) 3. MySQL (Elecronic
resource ) 4. Application software—Development. I. Title.
TK5105.888.W36116 2005
005.2’762—dc22
2005014955
Copyright © 2006 Pearson Education, Inc.
All rights reserved. Printed in the United States of America. This publication is protected by copy-
right, and permission must be obtained from the publisher prior to any prohibited reproduction,
storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical,
photocopying, recording, or likewise. For information regarding permissions, write to:
Pearson Education, Inc.
Rights and Contracts Department
One Lake Street
Upper Saddle River, NJ 07458

ISBN 0-13-186716-4
Text printed in the United States on recycled paper at R.R. Donnelly in Crawfordsville, IN.
First printing, September 2006
Contents

Introduction xxiii
Target Audience xxiii
About PHP xxiv
Layout xxiv
Before You Begin xxv
Acknowledgments xxv
In Closing xxvi

■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■

PART I The Basics of PHP


■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■

Chapter 1 Getting Started with PHP 3


Your First PHP Programs 3
Entering PHP Scripts 6
Marking Sections of PHP Code 6
Mixing PHP and HTML 6
Statements and Comments 8
How to Store Data 9
Entering Basic Types in PHP 10
Numbers 10
Strings 12
Booleans 15
Some Very Useful Functions 16
nl2br 16
var_dump 17
print_r 17
var_export 18
Summary 18

V
Contents
vi

Chapter 2 The PHP Language 19


More on Entering Strings 19
More on Data Types 21
Arrays 21
Objects 22
Special Types and Values 23
Type Conversions 24
Basics 24
Specific Type Conversions 25
Useful Type Conversion Functions 28
Variables and Constants 30
Defining Constants 30
By Value and by Reference Variables 30
Variable Scope 32
Variable Lifetime 32
Predefined Variables 33
Expressions and Operators 33
Operators: Combining Expressions 33
Combining Expressions and Operator Precedence 40
Control Structures 42
if Statements 42
switch Statement 42
while/do…while Loops 44
for Loops 45
foreach Loops 46
Interrupting Loops 46
Summary 47

Chapter 3 Code Organization and Reuse 49


Basic Code Reuse: Functions 49
Defining and Calling Functions 50
Passing Parameters to Functions 52
Returning Values from a Function 57
Variable Scope Inside of Functions 59
Function Scope and Availability 62
Functions as Variables 64
Intermediate Code Reuse: Using and Including Files 65
Organizing Code into Files 65
Choosing Filenames and Locations 67
Including Your Library Files in Script 69
Using Inclusion for Page Templating 75
Summary 76
Contents
vii

Chapter 4 Object-Oriented Programming 77


Moving Beyond Libraries 77
Object-Oriented Programming 81
Some Basic Terminology 81
The Basics of Objects in PHP 82
Initializing and Cleaning Up Objects 86
Visibility: Controlling Who Sees Things 88
Adding Static Data to Classes 91
Extending Objects 95
Extending Existing Classes 95
Visibility Revisited 96
Reimplementing Methods from Our Base Class 97
Making Classes Act the Same: Polymorphism 98
Other Features 107
Comparing Objects 107
Cloning Objects 107
User-Friendly Output 108
Type Hinting 109
Autoloading 110
Summary 111

Chapter 5 Working with Arrays 113


Arrays Revisited 113
Creating Arrays and Adding Data 114
Accessing Elements in Arrays 117
Deleting Elements and Entire Arrays 119
Counting Elements in an Array 120
Iterating Over Elements in an Array 120
foreach Loops 120
Regular Loops 121
Internal Loop Counters and each, next, prev, pos, and reset 122
The array_walk Method 124
Multi-Dimensional Arrays 125
Operations on Arrays 127
Sorting Arrays 127
Other Array Operations 130
Summary 132

Chapter 6 Strings and Characters of the World 133


Strings and PHP 133
How PHP Interprets Strings 134
Character Sets and Unicode 134
ASCII 134
The ISO 8859 Character Sets 134
Far Eastern Character Sets 135
Contents
viii

Unicode 135
Unicode Encodings 136
Making Sense of It All in PHP 136
Working with Other Character Sets 136
Trouble Rears Its Ugly Head 138
How We Will Work with Characters 139
Configuring PHP for Unicode 140
Installation and Configuration of mbstring and mbregex 140
Function Overloading 141
Operating on Strings 141
Getting Information 141
Cleaning Up Strings 143
Searching and Comparing 144
Extraction 148
Case Manipulation 149
Character Encoding Conversions 150
Summary 150

Chapter 7 Interacting with the Server: Forms 151


An Example of Forms 151
Working with HTML Forms 154
Adding a Form to Your Page 154
How Data Is Submitted 157
Accessing the Form Data Within Script 159
Character Sets and Forms 161
Working with the Server 162
Server Considerations 162
Server Variables 162
Environment Variables 167
Redirecting the User 168
Summary 170

■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■

PART II Database Basics


■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■

Chapter 8 Introduction to Databases 173


What Are We Talking About? 173
The Basics 174
Relational Databases 175
Motivations for Using a DBMS 175
The Case Against Simple Files or Spreadsheets 176
Database Servers 176
Major Database Servers 177
MySQL 177
PostgreSQL 178
Oracle Database 178
Contents
ix

Microsoft SQL Server 178


Other Servers 178
How to Select a Database Server 179
Thinking About Your Data 179
Capabilities 179
Performance 179
Accessibility from Within PHP 180
Cost 180
Our Choice 180
Common Interfaces 181
Summary 181

Chapter 9 Designing and Creating Your Database 183


What to Put into the Database 183
Organizing Your Data 185
Primary Keys 185
Choosing Data Types 186
Organizing Your Data into Tables 189
Indexes for Faster Searching 191
An Introduction to SQL 192
Creating Databases 193
Talking to the Database Server 193
Connecting and Authenticating 194
Creating the Database 194
Setting User Permissions 196
Preparing to Create Users 197
Creating a User 198
Deleting Users or Removing Privileges 199
Creating Tables 199
SQL Data Types 199
The Database Server Client Lifecycle 203
Creating the Table 204
Table Storage Engines 206
Creating Indexes 207
Foreign Keys and Cascading Deletes 207
Deleting Tables and Databases 209
Summary 210

Chapter 10 Using Databases: Storing and Retrieving Data 211


Before We Begin 211
Inserting Data into Our Tables 212
The INSERT INTO Statement 212
Bulk Data Insertion 213
Data Type Entry 215
Contents
x

Retrieving Data from Tables 216


Basic Syntax 217
Combining Table Data Upon Retrieval 220
Sorting Retrieved Data 223
Fetching a Few Rows at a Time 224
Modifying Data in Your Tables 225
Deleting Data from Tables 226
Summary 227

Chapter 11 Using Databases: Advanced Data Access 229


Transactions 229
The Problem 230
The Solution 231
Writing Transactions 232
A More Complicated Problem 232
More Advanced Queries 235
Combining Expressions 235
Specifying Sets and Ranges of Values 236
Fetching Unique Values 237
SQL Functions in Queries 238
Grouping Aggregate Function Data 243
Modifying Table Schemas 244
Summary 245

Chapter 12 PHP and Data Access 247


Getting Ready 247
Connecting and Authenticating 249
Sequence of Events 249
Making the Connection 250
Setting the Connection Character Set 252
Executing Queries 252
Retrieving Data 252
Validating User Input 255
Inserting, Deleting, and Updating Data 257
Transactions 259
Errors from mysqli 260
Queries a Go-Go 262
Bound Parameters 263
Bound Results 264
Old-School Interfaces 265
The Basics of Procedural Database Interfaces 265
Persistent Connections 268
Summary 268
Contents
xi

■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■

PART III Planning Web Applications


■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■

Chapter 13 Web Applications and the Internet 273


A Closer Look at the World Wide Web 273
The Internet: It’s Less Complicated Than You Think 274
Computers Talking to Computers 274
The Hypertext Transfer Protocol 276
MIME Types 279
Secure Sockets Layer (SSL) 279
Other Important Protocols 282
Designing Web Applications 282
Terminology 282
Basic Layout 283
User Interface 284
Business Logic 285
Back End/Server 289
n-Tier Architectures 289
Performance and Stability 290
Summary 291

Chapter 14 Implementing a User Interface 293


User Interface Considerations 293
Understanding Your User Interface 294
Planning a User Interface 295
Helping Users in Trouble 298
Design Tips and Strategies 299
Implementing Your User Interface 299
Cascading Style Sheets (CSS) 300
Including Files 302
Code Libraries for User Interface Generation 305
Implementing a User Interface Driver 309
Summary 310

Chapter 15 User Management 313


How Users Connect to Our Application 313
Visitors Versus Known Users 316
Validating Users 317
Partial Versus Full Logins 317
Where to Store User Information 318
What to Store and What Not to Store 318
Summary 320
Contents
xii

Chapter 16 Securing Your Web Applications: 321


Planning and Code Security
Strategies for Dealing with Security 321
The Most Important Thing 322
Balancing Security and Usability 322
After Development Finishes 323
Our Basic Approach 323
Identifying the Threats 323
The Threats 323
The Forces of Evil 326
Securing Your Code 327
A Golden Rule 327
Filtering Input 327
Code Organization 334
What Goes in Your Code 334
File System Considerations 335
Code Stability and Bugs 336
Execution Quotes and Exec 336
Summary 337

Chapter 17 Securing Your Web Applications: 339


Software and Hardware Security
Securing Your Web Server and PHP 339
Keep the Software Up-to-Date 340
php.ini 341
Web Server Configuration 341
Virtual Servers 342
Commercially Hosted Web Applications 344
Secure Sockets Layer (SSL) 345
Using SSL in PHP 345
Database Security 346
Users and the Permissions System 346
Sending Data to the Server 347
Connecting to the Server 347
Running the Server 348
Protecting the Network 348
Firewalls 348
DMZs 349
Educate Yourself About Network DoS and DDoS Attacks 349
Computer and Operating System Security 350
Keep the Operating System Up-to-Date 350
Run Only What Is Necessary 350
Physically Secure the Server 350
Disaster Planning 351
Summary 351
Contents
xiii

■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■

PART IV Implementing Your Web Application


■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■

Chapter 18 Error Handling and Debugging 355


How Errors Are Born 355
Errors from PHP 356
Bugs in Our Code 357
External Errors 358
How PHP Manages Errors 359
How PHP Displays Errors 359
Which Errors PHP Generates 360
Working with Errors 361
Configuring PHP Error Handling 367
Exceptions 367
Exception Basics 368
Working with Exceptions 370
Unhandled Exceptions 373
Extending Exceptions 374
Debugging 377
Instrumenting Your Code 377
Source Code Debuggers 379
Summary 380

Chapter 19 Cookies and Sessions 381


Cookies: Tasty and Useful 381
Basic Operation 382
How Cookies Work 385
Controlling Cookie Validity 386
Deleting Cookies 387
Cookie Arrays 387
What to Place into Cookies 388
Weight Watchers 388
Sessions 389
Basic Usage 390
Configuring PHP for Sessions 392
How the Session ID Is Transmitted 393
Storing Data with the Session 394
Page Caching 397
Destroying Sessions 399
How Session Storage Works 400
Session Security 405
Obtaining the Session ID 405
Limiting Damage from a Compromised Session ID 406
Summary 408
Contents
xiv

Chapter 20 User Authentication 409


Planning for Members 409
Web Server-Provided Authentication 412
Basic HTTP Authentication 412
Microsoft Windows Authentication Schemes 417
Implementing Our Own Authentication 419
Configuring the Database to Handle Logins 419
Adding New Users 420
Logging In Users 430
Updating Pages That Require a Logged In User 437
Logging Out Users 441
Deleting Users 443
Summary 444

Chapter 21 Advanced Output and Output Buffering 447


Globalization and Locales 447
Locales and Their Properties 448
Learning the User’s Locale 448
Setting the Locale of the Current Page (Unix) 450
Setting the Locale of the Current Page (Windows) 451
Learning About the Current Locale 453
Formatted Output 454
Formatting Numbers 455
Currencies 455
Other Formatting Functions 458
Output Buffering 461
How it Works 461
Using Output Buffering 462
Writing Your Own Handler 463
Summary 464

Chapter 22 Data Validation with Regular Expressions 467


Using Regular Expressions 467
What Are Regular Expressions? 468
Setup 468
Testing It 469
Basic Searches 470
Character Classes 471
Boundaries 472
The Dot 473
Repeating Patterns 474
Grouping and Choice 475
Tricks and Traps 475
Contents
xv

Data Validation with Regular Expressions 476


Validating Usernames 476
Matching Phone Numbers 477
Matching Postal Codes 477
Matching E-Mail Addresses 478
Other Regular Expression Functions 479
ereg_replace 479
Split 481
Summary 482

Chapter 23 XML and XHTML 483


XML 483
What Is XML? 484
Why Use XML? 485
Basic Terminology 486
The Structure of XML Documents 486
Namespaces 491
Validating XML 493
Related Technologies 495
Working with XML in PHP 496
Using SAX or DOM 497
Using the DOM 497
XHTML 510
Why XHTML? 511
How to Work with XHTML 511
Converting to XHTML 513
Summary 514

Chapter 24 Files and Directories 515


Accessing Files 515
Opening Files 515
Closing Files 518
Reading Files 518
Writing to Files 521
File Permissions and Other Information 523
Deleting and Renaming Files 525
Accessing Directories 525
Path Manipulation 526
Using Classes to Browse Directory Contents 527
Using Functions to Browse Directory Contents 528
Changing the Current Directory 528
Creating and Removing Directories 528
Security Considerations 529
File Access Considerations 529
Summary 531
Contents
xvi

Chapter 25 File Uploading 533


Uploading User Files 533
How File Uploading Works 534
Configuring PHP for Uploading 534
The Client Form 535
The Server Code 537
Limiting Uploaded File Size 540
Handling Multiple Files 541
A File-Uploading Example 543
Setting Up 543
The New Account Form 544
Creating the New Account 544
Viewing the User Data 548
Fetching the Image from the Database 550
Security Considerations 552
Trusted Users Only 552
Denial of Service 552
File Validation 552
Malicious Filenames 553
Summary 553

Chapter 26 Working with Dates and Times 555


Sources of Dates and Times 555
PHP 556
The Operating System 556
The Database Server 556
Web Pages and Users 557
Dates and Times in PHP 558
Timestamps in PHP 558
Getting the Date and Time 559
Validating Date and Time 563
Comparing Dates and Times 564
Outputting Formatted Dates and Times 567
A Problem with Timestamps 571
More Dates and Times in Database Servers 572
Date and Time Ranges in Common Database Servers 572
Adding or Subtracting Intervals 572
Parsing Dates in the Database 573
MySQL and Timestamps 573
Summary 574
Contents
xvii

Chapter 27 XML Web Services and SOAP 575


XML Web Services 575
Setting the Stage 576
Enter XML Web Services 576
Finding Web Services 577
How Web Services Work 578
SOAP 578
WSDL 579
HTTP 586
XML-RPC 587
Using Web Services in PHP 587
Selecting a Web Service 587
Configuring PHP 589
Working with the Service 589
Sample: Working with the Google APIs 594
Setting Up to Use the Google APIs 594
Learning More About the Service 594
How the Search Works 596
Searching for Keywords 597
Summary 602

Chapter 28 Using PEAR 603


Introduction to PEAR 603
Library of Code 604
PEAR Foundation Classes 604
Support Community 604
PECL 604
Installation and Configuration 604
Unix Users 605
Windows Users 605
Basic Commands 607
Getting Help 607
Listing Packages 608
Downloading and Installing Packages 609
Getting Information 610
Upgrading Existing Packages 611
Uninstalling Packages 612
Configuration Options for PEAR 612
Example: Using the Date Class 613
Installation 613
Basic Use 613
Further Examples 614
Summary 616
Contents
xviii

Chapter 29 Development and Deployment 617


Coding Standards 617
Worrying About Style 617
Developing a Coding Standards Document 619
Holy Wars 622
Other Considerations 623
Source Code Control 624
What’s My Motivation? 624
How They Work 624
Choosing a Source Code Control System 628
Working with Source Code Control 629
Testing 631
Why Bother to Test? 631
Unit Testing 632
Performance and Load Testing 635
Pest Control 637
Deployment 638
Test Servers 638
Scripting and Automating the Process 639
Deploying to the Live Server 639
Summary 640

■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■

PART V Sample Projects and Further Ideas


■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■

Chapter 30 Strategies for Successful Web Applications 643


Singleton Objects 643
Session Management 646
Configuration 646
Security 647
Putting It All Together 648
A Holistic Approach to Error Handling 650
User Versus Application Errors 650
Replacing the Default Handlers 653
Displaying Errors to Users 657
Creating New Exception Classes 659
Database Connection Management 660
A Better Approach 662
The Best Approach 664
A New and Improved String Escaping Function 666
PHP Configuration Settings 667
General Settings 667
Multiple-Byte String Settings 667
Error Settings 668
Database Settings 668
Summary 668
Contents
xix

Chapter 31 An Appointment Manager 671


Overview 671
Installing and Running the Sample 673
Structure and Page Progression 673
Page Structure 674
Database Layout 676
UI Strategy 678
Complete File Listing 680
Code Walkthrough 681
The AppointmentManager Class 682
Handling Dates and Times 687
Processing Forms and Page Progression 690
Showing a Week and a Month 697
Suggestions/Exercises 701
Change the Daily and Weekly Views 702
Monday–Sunday Weeks 702
Delete or Move Appointments 702
Convert to PEAR Date Class 703
Allow Overlapping Appointments 703
Make System Multiuser 703
Summary 703

Chapter 32 A Blogging Engine 705


Overview 705
Installing and Running the Sample 707
Structure and Page Progression 708
Page Layout 708
Database Structure and Notes 710
UI Strategy 712
Complete File Listing 713
Code Walkthrough 715
User Interface Generation 715
User Management 719
Tracking Logged In Users 726
Managing Entries and Comments 732
Suggestions/Exercises 741
Improve User Listing on Home Page 741
Allow Anonymous Comments 741
Hierarchical Comments 741
Have User Creation Use Transactions 742
Implement a New strip_tags Function 742
Summary 743
Contents
xx

Chapter 33 An Ecommerce Application 745


Overview 745
Installing and Running the Sample 747
Structure and Page Progression 748
Core Structure of the Sample 749
Page Layout
750
Database Structure 752
UI Strategy 756
Complete File Listing 758
Code Walkthrough 760
Browsing Products 760
Implementing the Shopping Cart 763
Progressing Through Checkout 767
Submitting Orders 778
Security 786
Payment Processing 786
Suggestions/Exercises 786
Skip Shipping Info 787
Post Order Processing 787
Admin Pages 787
Order Status/Cancel Order 787
Summary 787

■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■

PART VI Appendixes
■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■

Appendix A Installation/Configuration 791


Installation 791
Web Server 791
Database Server 797
PHP 803
Configuration 812
Web Server 812
Database Server 813
PHP 814
Summary 815

Appendix B Database Function Equivalents 817


Working with Databases 817
Listing Available Databases 817
Listing Tables in a Database 818
Describing a Table 818
Data Description and Creation 818
Creating Databases to Work with UTF-8 818
Setting the Connection to UTF-8 819
Contents
xxi

Auto-Incrementing Fields 819


Date/Time Column Types 819
Binary Column Types 820
Large Text Column Types 820
Bulk Data Insertion 820
Other Functions and Interesting Notes 821
Substring Extraction 821
String Concatenation 821
NOW 821
Date Functions 821
Formatting of Date/Time Output 822
The LIMIT Clause 822
Summary 822

Appendix C Recommended Reading 823

Index 825
This page intentionally left blank
Introduction

T his is the book I wish I had a couple years ago when I sat down and decided to
learn something about web applications. The transition from programming standard
window-system GUI applications to writing dynamic web applications was surprisingly
complicated. Extremely productive languages, such as Personal Home Page (PHP), make
the transition easier, but the learning curve remains steep.
With that in mind, I sat down to write this book and explain how to use the various tech-
nologies that go into writing web applications. I have made every mistake possible while
learning about PHP and databases, and have therefore tried to incorporate as much of
what I learned into this book. Far too many books published these days are merely a
reprint of existing documentation or Unix man pages, and I truly wanted to see something
different in print.
The technologies, however, are only half the battle. Without strategies or systematic
approaches to design and implementation, applications are doomed to an expensive
and messy existence at best—or failure at worst. Therefore, this book focuses on a lot of
things you might not see covered to the same extent in other books—design, testing, and
security.

Target Audience
This book is targeted at people who need or want to write a web application. You might
be a corporate developer looking to build an intranet application for your company or an

xxiii
Core Web Application Development with PHP and MySQL
xxiv

Internet web application for customers. You might be a consultant helping a small busi-
ness develop a web store, or just a hobbyist looking to learn more about web applications
and write one of your own.
The assumption is that you have at least a passing familiarity with programming,
although this book by no means expects you to be an expert. An understanding of basic
programming constructs, such as variables and functions, and a basic understanding of
HTML should be more than sufficient.
Because I knew next to nothing about databases when I started learning about web appli-
cation programming, I likewise expect no more of the reader. This book covers databases
from basic terminology and design to basic and advanced queries, with an appropriate
balance between clear-and-simple instruction and interesting examples to help you in
your development.

About PHP
PHP began in 1994 as a series of scripts called PHP/FI (Personal Home Page/Forms
Interpreter), and it was written by a fellow named Rasmus Lerdorf to help him manage
documents on his web site. Over the years, PHP grew into something more serious. In
1997, a second version of the system came out with additional functionality.
In late 1998, PHP 3.0 was released, leading to a major rewrite of the code and the involve-
ment of two new developers—Zeev Suraski and Andi Gutmans. The goal was to support
progressively broader and more complex applications on the web. In early 2000, version
4.0 was released. Based on a new language engine called the Zend Engine, this version
had much better performance and increased code modularity. By late 2004, the much-
evolved version 5.0 was released. It included many new features, such as new language
constructs, broader web server support, sessions, and additional third-party extensions.
Among the new language features was a significantly improved and expanded object-
oriented programming model, which this book uses extensively. Somewhere along the
way, PHP ceased to refer to “Personal Home Page” and came to mean “PHP Hypertext
Preprocessor,” a so-called recursive acronym. (The acronym actually forms part of the
term it defines!)
PHP is a remarkably productive language—you can sit down and crank out (yes, that’s
the technical term) large amounts of code in a short period of time, and this productivity
is what drew me to it some years back. With PHP, I was able to put together surprisingly
robust and dynamic travelogues of my journeys to various countries with relatively little
code.
The one possible “fly in the ointment” is that the language can be quirky compared to
other programming languages—especially if you, like me, come from a background of
languages more similar to C/C++, Java, or Visual BASIC. In fact, many of the things cov-
ered in this book are the result of my sitting around and scratching my head for a couple
of hours. However, after you become comfortable with it, the language proves fun to
write and is surprisingly powerful.

Layout
This book is divided into six parts, which represents the logical progression of writing
web applications.
Part I, “The Basics of PHP,” covers the PHP language itself, starting with descriptions
and discussions of the most basic types of language. Part I then moves on to functions,
Introduction • Acknowledgments
xv

code structure, and object-oriented programming—before finishing off with a discussion


of arrays and strings.
Part II, “Database Basics,” covers databases, starting with terminology and progressing
through design and data definition. Part II finishes by describing the use of databases and
tables, ranging from the most basic queries to transactions and functions.
Part III, “Planning Web Applications,” takes a step back from coding to discuss the
design of your web applications. Many people get so involved in writing their code that
they forget to sit down and actually think about it in advance. These chapters (hopefully)
give you something to think about as you begin. This part also focuses heavily on secur-
ing your applications, as it is not something to be taken lightly.
Part IV, “Implementing Your Web Application,” discusses the more advanced language
features and concepts required to move beyond simple PHP and databases into writing
web applications, covering topics such as errors, sessions, and XML—including plenty of
sample code.
Part V, “Sample Projects and Further Ideas,” presents three full web application samples
that start with a simple appointment management system, progress through a web log
system, and finish with an ecommerce store. These samples incorporate much of what the
book has covered and are designed to be robust. Instead of killing large numbers of trees
and listing all the code for the samples, you can download and run them. The book
shows you only the most salient sections of the code and leaves you to download and run
them in completion.
Part VI, “Appendixes,” discusses the installation of the necessary software to run your
web applications and how to perform various database actions on different database
engines, and suggests some additional reading material.

Before You Begin


Before you begin reading the meat of this book, please take a moment to open the CD
that accompanies this book and copy the source code to your computer. The phpwasrc/
directory contains the initial files you need.
In addition to the full source code (and installation instructions) for the three large sam-
ples from Part V of the book, there are also small snippets of code to accompany many of
the chapters in the book. You can run these, debug them, or change and play with them
to further help you learn how the language works.
Beyond the sample sources, the CD contains versions of PHP, the Apache HTTP Server,
and MySQL that you can use to install the software on your local machine. Instructions
are included on the CD.

Acknowledgments
I would like to thank the Academy for all the wonderful…gosh…I mean…what a rush!
Oh wait, wrong speech.
In all seriousness, no book can be written without a lot of help, and this is no exception.
Prentice Hall and my editor Mark Taub both deserve a huge amount of thanks for help-
ing me realize a dream and working with me on this book. The freedom and opportunity
to write the book I wanted to write were never threatened, and they have been amazing
at answering questions as I sent them.
Core Web Application Development with PHP and MySQL
xxvi

The technical review team of Kristine Kuch, Matthew Leingang, and Kimberly Jenson are
owed a huge debt of thanks. Never afraid to call me on stupid mistakes or bad writing or
short with praise and compliments, these people have taught me tons and have helped
me grow as both a web applications programmer and author over the past six months.
Finally, none of this would be possible without the support of my wife Samantha, who
encouraged me repeatedly to do more writing in the first place and lovingly nudged me
on those evenings when I swore I would never look at another computer again and was
sick of typing.

In Closing
I hope that you enjoy reading this book. I certainly hope that it helps you in your web
application programming endeavours and also provides at least some reading enjoyment.
I am a terribly chatty person, and always love to hear from people; therefore, if you have
any comments on the book or suggestions of things to add or treat differently, I’d be
delighted to hear from you at [email protected].
PART I
The Basics
of PHP
This page intentionally left blank
1
Getting Started
with PHP

B y now, you have managed to get PHP running on your server or workstation and
are ready to start writing scripts in PHP. If you have not, or you are still having problems,
please see Appendix A, “Installation/Configuration,” for more details. In this chapter, we
are going to write our first programs using Personal Home Page (PHP), and learn about the
basics of working with the language.
Over the course of this chapter we will
• Write a few basic PHP programs and learn how to enter and process PHP scripts
• See the basics of how the language is structured and how to comment your code
• Learn about some of the more common and basic data types in PHP
• Learn about some useful functions that we will use throughout this book

Your First PHP Programs


PHP is an interpreted scripting language, meaning that the language engine simply runs the
scripts you have written with no necessary intermediate steps to compile or convert them
into binary formats. Most of the scripts that will make up your web applications go in the
same place as your HTML content files. Files containing PHP script will typically have a
.php extension, although many people still use the older extensions—.php3 and .phtml.
Where you place these files will depend on how you have configured your web site and
what extension the web server will use to pass the file to the PHP interpreter. We will
refer to this location as the document root.

3
Core Web Application Development with PHP and MySQL
4

When the web server receives a request for an appropriately named file, it passes this to
the PHP engine, which then processes the file one line at a time. For lines that do not
contain PHP code (typically, lines containing HTML markup), the server emits them
untouched and executes any PHP script code as it is seen. With this in mind, we write
our first program, which is a mixture of PHP and HTML.
<html>
<head>
<title>My First PHP Program</title>
</head>
<body>

<?php
echo "Hello Everybody!";
?>
</body>
</html>

If we type this into a file called firstprogram.php and put it in our document root directory,
we can then type the URL for the path to this file (for example, http://localhost/
gettingstarted/firstprogram.php). We should then see something similar to Figure 1-1.

Figure 1-1: Your first PHP program in action.

If you have problems getting the script to run correctly, here are a few things you should
investigate:
• Make sure you entered the URL to the script file correctly, making sure that the server
name is valid.
Do not forget that the path gettingstarted is relative to the document root directory
for the web site. So, if our web site’s root directory were c:\inetpub\wwwroot or
/home/samplesite/www, then our directory in the preceding example would be
c:\inetpub\wwwroot\gettingstarted or /home/httpd/www/gettingstarted.
1 • Your First PHP Programs
5

• If you see just the code of your script printed onscreen, chances are that your web
server has not been configured to recognize .php files as needing to be sent to the PHP
interpreter.
• If you get an error saying that the host could not be found, then you should make sure
that the web server is actually running. See Appendix A for more information.
Most of the file is simply HTML text. As we have said, the PHP language engine outputs
any text it sees and looks for PHP code sections. In the preceding file, the PHP code is
demarcated by the tags
<?php
...
?>

When the PHP language engine sees these two tags, it processes the script and takes any
appropriate actions. When the script portion ends, it resumes output of HTML.
To learn more about our PHP installation, we will write a small script in our next program
that uses a helpful little tool. This function, called phpinfo, is used as follows:
<?php
phpinfo();
?>

This script produces output similar to that seen in Figure 1-2. (We did not have to use
HTML headers or markup since the phpinfo function emits these for us.)

Figure 1-2: Learning about our PHP interpreter with the phpinfo() function.
Core Web Application Development with PHP and MySQL
6

Entering PHP Scripts


Before we delve too deeply in to the PHP language, we will look at how to enter scripts
and how code interacts with HTML markup.

Marking Sections of PHP Code


There are a few ways to indicate that a section of the input file contains PHP script. The
most common way is as follows:
<?php
echo "Hello Everybody!";
?>

This method is safe for both XHTML and XML files; therefore, it is the method we will use
throughout this book.
Another way to demarcate PHP script is as follows:
<?
echo "Bonjour tout le monde!";
?>

This is called using short tags. Short tags are available only if the short_open_tag setting
is enabled in your php.ini configuration file (see Appendix A). The use of this style is gen-
erally discouraged, as it does not save you much in typing and can create problems as you
move your code from server to server, where one of them might not have short tags
enabled.
A third way of entering script is
<script language="php">
echo "Ciao a tutti!";
</script>

This method does not buy us very much and is generally used much less than the first
style.
One final style of inputting script exists to support some older graphical HTML editing
programs that are unable to understand script directives very well and would move script
around when they generated HTML for user input. However, some of these editors could
support tags by marking code as ASP script. To let users continue to use these editors, you
can mark PHP script using these ASP tags:
<%
echo "Guten Tag alle!";
%>

ASP tags can only be used if the asp_tags setting is enabled in the php.ini configuration
file.
Even though we will use the first style of tags, we have shown you all the possible types
to prepare you for other codes you may encounter.

Mixing PHP and HTML


There is nothing that requires large blocks of PHP code when writing HTML and PHP:
You are completely free to mix the markup and script as much as you wish. For example,
1 • Entering PHP Scripts
7

you might want to personalize a greeting message ($userName is a variable, which we will
introduce more formally soon):
<?php
$userName = "Chippy the Chipmunk";
?>

<p align='left'>
Hello there, <b><?php echo $userName; ?></b>
</p>

A shortcut exists for this particular usage. It involves the short tags discussed in the previ-
ous section along with an equals sign (=):
<?= $userName ?>
This is the same as typing
<?php echo expression; ?>

This can be a handy way to save a bit of typing when you are injecting several expressions
into your HTML. However, we will continue to avoid using short tags and stick with the
normal syntax.
The flexibility available when mixing PHP and HTML allows us to be creative when we
get into more advanced language constructs. (These concepts will be introduced in
Chapter 2, “The PHP Language.”)
<?php

if ($file_received_successfully === TRUE)


{
?>
<p align='center'> Thank for your contribution </p>
<?php
}
else
{
?>
<p align='left'>
<font color='red'>
<b>Error: The file was not correctly received.</b>
</font>
</p>
<?php
}

?>

This, like some other things we will encounter as we learn about web application pro-
gramming with PHP—while perfectly valid in PHP—is probably something we should
Core Web Application Development with PHP and MySQL
8

use sparingly. We should write code that is legible and easily maintainable whenever
possible.

Statements and Comments


Statements in PHP are separated by a semicolon (;). Statements can be grouped together
by wrapping them in brackets ({}), which is sometimes called a block of code. Any num-
ber of statements can be placed on one line. Individual items (or tokens) within a state-
ment can be separated by arbitrary amounts of whitespace (space, newline characters, or
tabs). Statements can even span more than one line.
<?php

$x = 123; $y = 456; $z = "hello there"; $a = "moo";

{
echo "This is a group of statements";
$m = "oink";
}

$userName
=
"Chippy the Chipmunk"

;
?>

Just because one can do this, however, does not mean it is recommended. Programmers
are always encouraged to make their code legible.
The end of a section of PHP script is also a valid way to terminate a statement:
<?php echo "Semi-colon not necessary here!" ?>

There are three basic styles for entering comments in PHP:


<?php
/*
* This is our first style of comment.
*/
echo "Style 1";

//
// This is our second style of comment. It is "single line"
//
echo "Style 2";

#
# This third style is also "single line."
1 • How to Store Data
9

#
echo "Style 3";
?>

The first two styles are very common in higher-level programming languages, such as
C/C++, Java, and C#, while the latter style will be familiar to programmers of Perl and
shell scripts.
The first style of comments beginning with “/*” causes the PHP processor to ignore all
text until it sees a closing “*/” sequence. This can cause problems if you try to nest
comments.
<?php
/*
/**
* this is a comment.
*/
echo "This is some code";
*/
?>

Because of the nested comment, the processor stops treating the code as comment text at
the first “*/” token and reports and error at the second, because it no longer believes itself
to be processing comments.
The two types of single-line comments cause the PHP language processor to ignore all
code until the end of the current line or current PHP script section.
<?php
// all of this line is ignored.
echo "But this line prints just fine.";
?>

<?php #Comment!! ?><b>This prints</b><?php echo "this prints" ?>

How to Store Data


At some point, you will want to hold on to and manipulate data of varying sorts. This is
done in PHP by using variables. Variables are a place to store data for later use. They are
valid for the duration of the currently executing script.
PHP is different from many other languages, in that variables do not need to be declared
before they are used—to declare one, you simply assign it a value. Variable names in PHP
are represented by a dollar sign ($) followed by an identifier that begins with either a let-
ter or underscore, which in turn can be followed by any number of underscores, numbers,
or letters. Included in the set of letters permitted for variable names are some extended
characters, such as accented Latin letters. Other extended characters, however, such as
many Chinese characters seen in Japanese and Chinese alphabets, are not permitted.
<?php
$varname = "moo"; // ok
$var______Name = "oink"; // ok
$__12345var = 12345; // ok
Core Web Application Development with PHP and MySQL
10

$12345__var = 12345; // NOT ok - starts w/ number


$école = "Rue St. Jacques"; // ok - é is an extended char
$ = "car"; // NOT ok - has invalid chars
?>

In versions of PHP prior to version 4, variables would be declared at their first use instead
of their first assignment, which often proved tricky when debugging code.
<?php

$cieling = "roof"; // whoops misspelled it!

echo "$ceiling"; // prints an empty string.

?>

Fortunately, PHP 5 prints a warning saying that, for instance, "$ceiling” has not been
assigned a value.

Entering Basic Types in PHP


Many programmers with experience in other languages find working with types in PHP
a slightly different and occasionally quirky experience. PHP is a richly typed language,
where each piece of data has a type associated with it, but variables are not declared as
having a particular type—the language engine determines the type to use based on a set
of rules ( leading some people to call it dynamically typed instead). We will now introduce
the most basic types and discuss how they are used.

Numbers
There are two basic types of numbers in the language: integer (int ) and float (float).
While many languages distinguish between single and double-precision floating-point
numbers, PHP does not—they are all 64-bit floating-point numbers with approximately 14
digits of precision. PHP does, however, support the keyword double in addition to float
for compatibility.
Integers are specified in code in octal (base-8), decimal (base-10), or hexadecimal (base-16)
notations.
<?php

$abc = 123; // decimal


$def = -123;
$ghi = 0173; // octal, value is 123 in decimal
$jkl = -0173; // octal, value is -123 in decimal
$mno = 0x7b; // hexadecimal, 123
$pqr = -0x7B; // hexadecimal, -123

?>
1 • Entering Basic Types in PHP
11

Integer precision varies largely by the underlying operating system, but 32 bits is com-
mon. There are no unsigned integers in PHP, so the maximum value for an integer is
typically larger than 2 billion. However, unlike other languages that overflow large
positive integers into large negative integers, PHP actually overflows integers to floating-
point numbers.
<?php
$large = 2147483647;

var_dump($large);

$large = $large + 1;

var_dump($large)
?>

The output of this script is


int(2147483647) float(2147483648)

In the previous snippet of code, we introduce the var_dump function, a powerful debug-
ging tool used to see both the type and value of a variable in PHP. We will return to this
later in the chapter in the section titled “Some Very Useful Functions.”
Even though we will discuss arithmetic operators such as addition, multiplication, and
subtraction in Chapter 2, in the section titled “Expressions and Operators,” we will take
time now to note that there is no integer division in PHP. Unlike some other languages,
for which the expression
5 / 2

would yield an integer result with the value 2, PHP would return the value 2.5, typed as
float. If you want the integer value result of a division operation, you need to cast the
value to an integer (see the section “Type Conversions” in Chapter 2) or use the round
function, which you can learn about via the PHP Online Manual.
Floating-point variables can be input in a few different ways:
<?php
$floatvar1 = 7.555;
$floatvar2 = 6.43e2; // same as 643.0
$floatvar3 = 1.3e+4; // same as 13000.0;
$floatvar4 = 5.555e-4; // same as 0.0005555;
$floatvar5 = 1000000000000; // too big for int ==> float
?>

One caution with floating-point numbers: Remember that they are only approximate val-
ues. Because of their limited precision, they are very close to the intended value but are
not always the value you would like.
Core Web Application Development with PHP and MySQL
12

For example, the value 2.5 will often be represented internally as 2.4999999999, or some-
thing similar. Thus, the following code will often prove problematic:
<?php

if (0.7 + 0.1 >= 0.8)


echo "Hoooray!";
else
echo "What???";

?>

Code snippets such as these often print "What???", depending on the exact implementa-
tion of floating-point numbers.
The recommendation is to avoid comparing specific floating-point values. Instead, you
should round them to the nearest integer value using round, or compare them against the
ranges of values.

Strings
A string is a sequence of characters. In PHP, these characters are 8-bit values. This is con-
venient for many Western languages but proves a bit problematic when trying to work
with systems using more complicated alphabets, such as Chinese. We will cover solutions
for this in more detail in Chapter 6, “Strings and Characters of the World.”
There are three ways to specify a string value.
Single Quoted
Single-quoted strings are sequences of characters that begin and end with a single quote (').
<?php echo 'This is a single-quoted string.'; ?>

To include a single quote within a string, you simply put a backslash in front of it. This is
called escaping the character.
<?php echo 'This is a single-quoted (\') string.'; ?>

If you actually want to print \' as output or if you want to end a string with a backslash
character, then you need to escape the backslash one more time.
<?php

echo 'This is a single-quoted string.';


echo '<br/>';
echo 'This is how to print a single quote: \' in a string.';
echo '<br/>';
echo 'And now to show a backslash in the output: [ \\\' ]';
echo '<br/>';
echo '\And now to terminate a string with a backslash\\';
echo '<br/>';

?>
1 • Entering Basic Types in PHP
13

The previous script produces the following output:


This is a single-quoted string.
This is how to print a single quote: ' in a string.
And now to show a backslash in the output: [ \' ]
\And now to terminate a string with a backslash\

No other escaping or expansion is supported. Therefore, in the previous code, \A just


prints out the two characters.
Double Quoted
Double-quoted strings are similar to single-quoted strings, except that the PHP language
processor actually dissects them to find and replace special escape sequences and
variables.
<?php echo "This is a double-quoted string."; ?>
In addition to the escape sequence \" required to insert a double quote within a double-
quoted string, PHP understands the following escape sequences:

Escape Output
\n Linefeed character (0x0a/10 in ASCII)
\r Carriage return character (0x0d/13 in ASCII)
\t Tab character
\\ Backslash
\$ Dollar sign character
\0octal-number A character identified by its value in the range 0–255,
specified in octal notation.
\xhexadecimal-number A character identified by its value on the range 0–255,
specified in hexadecimal notation.

No other escape sequences are supported, and (in the case of single-quoted strings) non-
matching sequences will simply print the backslash and the other character.
<?php
echo "This is a rich \"\$\$\" double-quoted string.";
echo "<br/>\n";
echo "This is a rich \042\x24\x24\042 double-quoted string.";
echo "<br/>\n";
echo "This won't quite do what \n\n you expect it to!";
echo "<br/>\n";
echo "Neither likely
will
this.";
echo "<br/>\n";
echo "\\ + A isn't a valid escape, so this will print \A";
?>
Random documents with unrelated
content Scribd suggests to you:
the last session of the legislature, the Department has placed groups
of convicts from the various State prisons at work improving roads in
different parts of the State. The plan will be extended as fast as
possible with the available appropriation and it is hoped that some
500 miles of earth road will be improved during the summer.
At present there are five convict squads on the roads. Three squads
have been sent out from Dannemora. They are all engaged in
Clinton County one squad improving a bad stretch of the old military
turnpike. Two more squads are out from Great Meadow, one working
on the Comstock-Whitehall road and the other on the Ticonderoga-
Schroon lake road in Warren county.
So far the plan has proved most successful. The convicts are keen
for the chance of work in the open air and the result to the counties
in which the work is being carried on is gratifying in improved traffic
conditions.
Several squads have been made up to be sent out from Auburn
prison, but an outbreak of scarlet fever in the institution has delayed
the plan. As soon as the quarantine is lifted many prisoners will be
put to work.
By the provisions of the new law the thirty-mile radius from the walls
of prisons within which convicts could be engaged in road work has
been removed, so that they may be employed in any part of the
State. In addition to this, for the first time an appropriation has been
made of $50,000 for carrying on the work of improving roads by
convict labor. Boards of Supervisors of the various counties are
applying to the Prison Department for convicts to improve roads in
the counties which are not included in the State macadamized
system.
Under the plan of Superintendent Riley the $50,000 will be spent in
improving earth roads rather than trying to build roads of macadam
because of the much greater use of the appropriation. Ten miles of
good earth road may be built for the amount required to construct a
single mile of macadam where gravel or other proper material for
surfacing is obtainable. It also costs less to maintain ten miles of
gravel road than one mile of macadam, declares Superintendent
Riley.
“After the $100,000,000 to which the State is pledged is expended
on the State highways there will be a very large percentage of the
roads in the State which will not be touched by this expenditure,”
said Superintendent Riley. It is for the good of these roads, many of
them of the greatest importance, that he wishes to direct the convict
road labor particularly. Hudson Republican, June 8.
NOTES
A new county workhouse costing $25,000 has been built at South
Range, Wis., on a tract of 160 acres, which will be worked by the
prisoners.

A modified form of self-government has been introduced at the New


Jersey State Reformatory at Rahway by Dr. Frank Moore.

Governor Major of Missouri will recommend legislation to provide for


a prison farm, 1000 acres in size to start with.

Road work by State prison convicts will start in a few weeks in


Wisconsin. The men will be paid a certain sum for their work.

Sir A. Conan Doyle recently visited Sing Sing, and agreed with
everybody but the legislators of the State of New York that Sing Sing
ought to go.
A commission has been authorized by the State of Pennsylvania and
appointed by the Governor, to consider revision of the penal laws.
Two of the members of the commission are Edwin M. Abbott of
Philadelphia and Warden McKenty of the Eastern Penitentiary.

On the first of July much more stringent regulations regarding the


sale and possession of cocaine and other habit-forming drugs came
into effect in New York State. A spectacular and effective campaign
is now being waged in New York City against dope-vendors.

More than seven hundred prisoners out of 2000 at San Quentin


prison have been taking correspondence courses given by the
University of California. Spanish is a favorite language to be studied.

At Sing Sing the new warden has started out well. He has given to
the inmates Saturday afternoon for recreation, and has introduced
base ball and other sports. If it works successfully the inmates will
have a recreation hour daily, at the close of the day’s work.

Several members of the board of managers of the Prison


Association of New York recently made a tour of inspection of
correctional institutions in New York, Pennsylvania and the Province
of Ontario, being the guests of Mr. Richard M. Hurd in his
automobile. The tour included about 1800 miles, and some twenty
correctional institutions, among them Clinton and Auburn State
Prisons in New York, the Prison Farm at Guelph, Ontario, the new
Central Prison site at Bellefonte, Pennsylvania, the State
Reformatory of Pennsylvania at Huntingdon, the Eastern
Penitentiary of Pennsylvania?, the State Prison at Trenton, New
Jersey, the Berkshire Industrial Farm and the State Industrial and
Agricultural Farm in New York, and about a dozen county jails. The
tour occupied two weeks, and gave a remarkable opportunity to
make careful and immediate contrasts of various institutions.

In New York State road work by convicts is assuming important


proportions. Superintendent of Prisons John B. Riley is strongly in
favor or the outdoor employment of prisoners on roads.

The Prison Commission of New York is investigating the charges of


Ex-Warden Clancy that drugs are smuggled into Sing Sing prison by
officers and others.

On July 4th, at Great Meadow Prison, six hundred inmates were


marched down to the prison ball field, one half mile from the prison,
under the supervision of inmate officers. The regular prison guards
were not used.

Miss Katherine B. Davis, commissioner of correction of New York


City, has been having plenty of activity in the administration of the
department. Several riots occurred at the Penitentiary in the early
part of July, following effective methods of reducing the amount of
“Dope” purveyed by the prisoners. More modern methods of
conducting the city’s correctional institution and a certain antagonism
to the new reform administration of the city’s correctional institutions,
also played a part. The riots were successfully overcome, and Miss
Davis was not only “on the job” but in the midst of it.

In Buffalo, N. Y., a new county jail is to be built for the detention of


prisoners prior to or during trial. The Prison Association of New York
is making a strong campaign for the erection of a thoroughly modern
jail with outside cells, as contrasted with the old traditional type of
inside cages, the prevalent American type of jail construction. In this
campaign the Association is cooperating with a group of the Board of
Supervisors of Erie county. Among those who have written long
letters advocating the outside cell type of construction are Professor
C. R. Henderson of the University of Chicago, Commissioner
Katherine B. Davis of New York, Dr. Hasting H. Hart of the Russell
Sage Foundation, Superintendent Frank Moore of the State
Reformatory of New Jersey. Amos W. Butler of Indiana, and Drs. S.
A. Knopf and G. M. Parker of New York City. The special committee
recently appointed by the Board of Supervisors will visit institutions
of both types of construction, among them the Prison Farm at
Guelph.

Because of the absence of any work under the proposed State-use


system which the prisoners could do, it was found necessary to
continue for the present the contract system at the State Prison of
New Jersey at Trenton, although by law all contracts should have
expired on June 30th.
There is agitation in Baltimore for a State Workhouse similar to that
of Occoquan, in the District of Columbia.
STATEMENT OF THE OWNERSHIP, MANAGEMENT, ETC. of THE
DELINQUENT.
Published monthly at New York, N. Y., required by the Act of August
24th, 1912.
NAME OF POST OFFICE ADDRESS
Editor, O. F. Lewis, 135 East 15th St., New York City
Managing Editor, O. F. Lewis, ” ” ” ” ” ” ”
Business Manager, O. F. Lewis, ” ” ” ” ” ” ”
Publisher, The National Prisoners’
” ” ” ” ” ” ”
Aid Association,
Owners, The National Prisoners’ Aid
” ” ” ” ” ” ”
Association,
There are no bondholders, mortgages, or other security holders.
O. F. LEWIS, Editor and Business Manager.
Sworn to and subscribed before me this 27th day of March, 1914.
H. L. McCORMICK, Notary Public No. 6, Kings County.
My Commission expires March 31, 1914.
Transcriber’s Notes

A number of typographical errors were corrected silently.


New original cover art included with this eBook is granted to the
public domain.
Issue number was corrected from 6 to 7
*** END OF THE PROJECT GUTENBERG EBOOK THE
DELINQUENT, VOL. IV, NO. 7, JULY, 1914 ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright
in these works, so the Foundation (and you!) can copy and
distribute it in the United States without permission and without
paying copyright royalties. Special rules, set forth in the General
Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree to
abide by all the terms of this agreement, you must cease using
and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project
Gutenberg™ works in compliance with the terms of this
agreement for keeping the Project Gutenberg™ name
associated with the work. You can easily comply with the terms
of this agreement by keeping this work in the same format with
its attached full Project Gutenberg™ License when you share it
without charge with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the United


States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it
away or re-use it under the terms of the Project Gutenberg
License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country where
you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of the
copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.
1.E.5. Do not copy, display, perform, distribute or redistribute
this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must, at
no additional cost, fee or expense to the user, provide a copy, a
means of exporting a copy, or a means of obtaining a copy upon
request, of the work in its original “Plain Vanilla ASCII” or other
form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt that
s/he does not agree to the terms of the full Project Gutenberg™
License. You must require such a user to return or destroy all
copies of the works possessed in a physical medium and
discontinue all use of and all access to other copies of Project
Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite
these efforts, Project Gutenberg™ electronic works, and the
medium on which they may be stored, may contain “Defects,”
such as, but not limited to, incomplete, inaccurate or corrupt
data, transcription errors, a copyright or other intellectual
property infringement, a defective or damaged disk or other
medium, a computer virus, or computer codes that damage or
cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES -


Except for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU
AGREE THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE,
STRICT LIABILITY, BREACH OF WARRANTY OR BREACH
OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE
TRADEMARK OWNER, AND ANY DISTRIBUTOR UNDER
THIS AGREEMENT WILL NOT BE LIABLE TO YOU FOR
ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE
OR INCIDENTAL DAMAGES EVEN IF YOU GIVE NOTICE OF
THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If


you discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person or
entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR
ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you do
or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission of


Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status by
the Internal Revenue Service. The Foundation’s EIN or federal
tax identification number is 64-6221541. Contributions to the
Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or
determine the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About Project


Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookfinal.com

You might also like