Skip to main content

PHP and MySQL: Create - Modify - Reuse

PHP and MySQL: Create - Modify - Reuse

Timothy Boronczyk, Martin E. Psinas (With)

ISBN: 978-0-470-19242-9

May 2008

341 pages

Select type: Paperback

Product not available for purchase


Learn everything about the dynamic power of PHP and MySQL in real-world applications with the practical information and step-by-step instructions in PHP and MySQL: Create - Modify – Reuse. The authors, experts in tune with common web development tasks, will guide you through several projects that are complete, tested, and ready to be implemented, so that you can understand by doing. Understand all aspects of design, such as portability, design flow, and integration, and become proficient at solving problems that developers face in everyday circumstances.

Introduction xi

Chapter 1: User Registration 1

Plan the Directory Layout 1

Planning the Database 2

Writing Shared Code 3

User Class 5


Templates 11

Registering a New User 12

E-mailing a Validation Link 17

Logging In and Out 21

Changing Information 25

Forgotten Passwords 28

Summary 30

Chapter 2: Community Forum 31

Design of the Forum 31

Designing the Database 32

Working with Permissions and Bitwise Operators 33

Updating the User Class 35

Code and Code Explanation 40

Adding Forums 41

Adding Posts 43

Displaying Forums and Posts 47

Pagination 55

Avatars 56

BBCode 59

Summary 62

Chapter 3: Mailing List 63

Design of the Mailing List 63

Choosing POP3 64

Designing the Database 65

Code and Code Explanation 66

The POP3 Client 66

The Configuration File 73

Account Management 73

Processing Messages 79

Processing the Digest 83

Setting Up the Mailing List 83

Summary 86

Chapter 4: Search Engine 87

Designing the Search Engine 87

Problems with Full-Text Search 88

Designing the Database 89

Code and Code Explanation 91

Administrative Interface 91

Crawler/Indexer 98

Front End 104

Summary 110

Chapter 5: Personal Calendar 113

Designing the Application 113

Designing the Database 114

Code and Code Explanation 115

Creating a Month-View Calendar 115

Creating a Day-View Calendar 120

Adding and Showing Events 121

Sending Reminders 129

Exporting the Calendar 130

Summary 135

Chapter 6: Ajax File Manager 137

Design of the Ajax File Manager 137

JavaScript and Ajax 138

The XMLHttpRequest Object 139

Code and Code Explanation 142

Main Interface 143

Client-Side Functionality 147

Server-Side Functionality 160

Summary 175

Chapter 7: Online Photo Album 177

Design of the Online Photo Album 177

Code and Code Explanation 178

Views 178

Helper Files 188

QuickTime Thumbnails 190

Thumbnail Caching 192

Summary 193

Chapter 8: Shopping Cart 195

Designing the Shopping Cart 195

Designing the Database 196

Code and Code Explanation 197

The ShoppingCart Class 197

Working with the Shopping Cart 201

Building the Storefront 209

Adding Inventory 217

Summary 238

Chapter 9: Web Site Statistics 239

Determining What to Collect 239

Designing the Database 241

Obtaining Data 242

Code and Code Explanation 244

Pie Chart 244

Bar Chart 248

The Report 253

Summary 264

Chapter 10: News/Blog System 265

Tables 265

Adding Posts 267

Generating the RSS 278

Displaying Posts 282

Adding Comments 285

Summary 289

Chapter 11: Shell Scripts 291

Designing the Script 292

General Shell Scripting Advice 293

Code and Code Explanation 294

The CommandLine Class 294

startproject 303

The Skeleton 313

Summary 314

Chapter 12: Security and Logging 315

Cross-Site Scripting 315

Path Traversal 318

Injection 320

SQL Injection 320

Command Injection 324

Weak Authentication 325

Logging 327

Preventing Accidental Deletes 330

Summary 332

Index 333

Code Downloads
Code downloads for this title are available here.
Code Downloads
Code downloads for this title are available here.
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Chapter 12
All Code for Book
ChapterPageDetailsDatePrint Run
Error in Code
login.php Line 21:

if ($user->userId && $user->password == sha1($_POST['password']))

Should be

if ($user->userId && $user->isActive && $user->password == sha1($_POST['password']))

Error in Code
Chapter 1, User Registration, the forgotpass.php file:

// store new password
$user->password = $password;

Should be:

// store new password
$user->password = sha1($password);

48Error in Text
echo htmlspecialchars($row['DESCRIPTION']) . '</li>';

Should be:

echo htmlspecialchars($row['DESCRIPTION']) . '</a></li>';

This appears again on page 53 as view.php and should be corrected there as well.

49Error in Text
echo htmlspecialchars($row['SUBJECT']) . '</li>';

Should be:

echo htmlspecialchars($row['SUBJECT']) . '</a></li>';

This appears again on page 53 as view.php and should be corrected there as well.

69Error in Text
Lower gray box on page:


should be


77Error in Text
manage.php code line 11 left off semicolon at the end of the line

The line should be:


79Error in Text
The case 'HELP' block needs to have a break statement

The code should read:

case 'HELP':
$response_file = 'help.txt';

129Error in Text
The section Sending Reminders
The notify.php code in the gray box

The 7th line down is missing ending single quote on the actual email address.
This is wrong in the book and in the download code.
(note the download code has different email address,
but they still forgot the single quote at the end).

in the book
define('EMAIL_ADDR', ';
and in the download code
define('EMAIL_ADDR', ';
It should be like
define('EMAIL_ADDR', '');


130Error in Text
notify.php, in the first gray box where it says mail,

mgs should be msg. This is wrong in both the book and download code

The book has it like this.
mail(EMAIL_ADDR, Reminders for $month/$day/$year $hour:$minute $am , $mgs);
It should be like this, (msg instead of mgs)
mail(EMAIL_ADDR, Reminders for $month/$day/$year $hour:$minute $am , $msg);

222Error in Text
The last word in paragraph 1 on p.222 is SystemOverflowException.
This should read System.StackOverflowException, as this is the error thrown at runtime when compiled code contains an infinite loop between two class constructors.

11309Error in Code
Reads: STEDRR.

Should be: STDERR

320Code Error
On page 320, at the top of the page there is a gray box section containing code,
The variable $target is not defined (line 10); This will give you an error.
The code should contain $template, not $target, on page 320. The correct code excerpt should be:
<?php define(TEMPLATE_DIR, '/srv/apache/example/templates/');
if (isset($_GET['t']))
$template = realpath(TEMPLATE_DIR . $_GET['t']);
if (isset($template) && strpos($template, TEMPLATE_DIR) !== 0 && file_exists($template)),
include $template;
include TEMPLATE_DIR . 'default.php';

323Error in Code
On page 323, about 12 lines down, there is a gray box illustrating a line of code. The sample should read:
'USER_ID = %d', $_POST['userid']);