Thông tin chi tiết
Preface xiii
1. Introduction to Dynamic Web Content 1
HTTP and HTML: Berners-Lee’s Basics 2
The Request/Response Procedure 2
The Benefits of PHP, MySQL, and JavaScript 5
Using PHP 5
Using MySQL 6
Using JavaScript 7
The Apache Web Server 8
About Open Source 9
Bringing It All Together 9
Test Your Knowledge: Questions 11
2. Setting Up a Development Server . 13
What Is a WAMP, MAMP, or LAMP? 13
Installing a WAMP on Windows 14
Overcoming Installation Problems 14
Testing the Installation 16
Alternative WAMPs 18
Installing a MAMP on Mac OS X 19
Some Final Tweaking 24
Other Alternatives 25
Installing a LAMP on Linux 25
Working Remotely 26
Logging In 27
Using FTP 27
Using a Program Editor 28
Using an IDE 30
Test Your Knowledge: Questions 32
3. Introduction to PHP 33
Incorporating PHP Within HTML 33
Calling the PHP Parser 34
This Book’s Examples 35
The Structure of PHP 36
Using Comments 36
Basic Syntax 37
Understanding Variables 38
Operators 42
Variable Assignment 45
Multiple-Line Commands 47
Variable Typing 49
Constants 50
The Difference Between the echo and print Commands 51
Functions 52
Variable Scope 53
Test Your Knowledge: Questions 58
4. Expressions and Control Flow in PHP 61
Expressions 61
Literals and Variables 62
Operators 63
Operator Precedence 64
Associativity 66
Relational Operators 67
Conditionals 70
The if Statement 71
The else Statement 72
The elseif Statement 73
The switch Statement 74
The ? Operator 77
Looping 78
while Loops 78
do .while Loops 80
for Loops 81
Breaking Out of a Loop 83
The continue Statement 84
Implicit and Explicit Casting 84
PHP Dynamic Linking 85
Dynamic Linking in Action 86
Test Your Knowledge: Questions 87
5. PHP Functions and Objects 89
PHP Functions 90
Defining a Function 91
Returning a Value 92
Returning an Array 93
Passing by Reference 94
Returning Global Variables 95
Recap of Variable Scope 96
Including and Requiring Files 96
The include Statement 96
Using include_once 97
Using require and require_once 97
PHP Version Compatibility 98
PHP Objects 98
Terminology 99
Declaring a Class 100
Creating an Object 101
Accessing Objects 101
Constructors 104
Writing Methods 105
Declaring Properties 106
Declaring Constants 107
Property and Method Scope in PHP 5 107
Inheritance 109
Test Your Knowledge: Questions 113
6. PHP Arrays . 115
Basic Access 115
Numerically Indexed Arrays 115
Associative Arrays 117
Assignment Using the array Keyword 118
The foreach .as Loop 119
Multidimensional Arrays 121
Using Array Functions 123
is_array() 123
count() 124
sort() 124
shuffle() 124
explode() 125
extract() 125
compact() 126
reset() 127
end() 128
Test Your Knowledge: Questions 128
7. Practical PHP . 129
Using printf 129
Precision Setting 131
String Padding 132
Using sprintf 133
Date and Time Functions 133
Date Constants 136
Using checkdate 136
File Handling 137
Checking Whether a File Exists 137
Creating a File 137
Reading from Files 139
Copying Files 139
Moving a File 140
Deleting a File 140
Updating Files 141
Locking Files for Multiple Accesses 142
Reading an Entire File 143
Uploading Files 144
System Calls 149
XHTML 151
The Benefits of XHTML 151
XHTML Versions 151
What’s Different? 152
HTML 4.01 Document Types 153
XHTML 1.0 Document Types 153
XHTML Validation 154
Test Your Knowledge: Questions 155
8. Introduction to MySQL . 157
MySQL Basics 157
Summary of Database Terms 158
Accessing MySQL via the Command Line 158
Starting the Command-Line Interface 159
Using the Command-Line Interface 163
MySQL Commands 164
Data Types 168
Indexes 177
Creating an Index 178
Querying a MySQL Database 183
Joining Tables Together 192
Using Logical Operators 194
MySQL Functions 194
Accessing MySQL via phpMyAdmin 195
Windows Users 195
Mac OS X Users 195
Linux Users 195
Using phpMyAdmin 197
Test Your Knowledge: Questions 198
9. Mastering MySQL . 201
Database Design 201
Primary Keys: The Keys to Relational Databases 202
Normalization 203
First Normal Form 204
Second Normal Form 206
Third Normal Form 208
When Not to Use Normalization 210
Relationships 211
One-to-One 211
One-to-Many 212
Many-to-Many 212
Databases and Anonymity 214
Transactions 214
Transaction Storage Engines 215
Using BEGIN 216
Using COMMIT 216
Using ROLLBACK 216
Using EXPLAIN 217
Backing Up and Restoring 218
Using mysqldump 219
Creating a Backup File 220
Restoring from a Backup File 222
Dumping Data in CSV Format 222
Planning Your Backups 223
Test Your Knowledge: Questions 223
10. Accessing MySQL Using PHP 225
Querying a MySQL Database with PHP 225
The Process 225
Creating a Login File 226
Connecting to MySQL 227
A Practical Example 232
The $_POST Array 234
Deleting a Record 235
Displaying the Form 236
Querying the Database 236
Running the Program 237
Practical MySQL 238
Creating a Table 238
Describing a Table 239
Dropping a Table 240
Adding Data 240
Retrieving Data 241
Updating Data 242
Deleting Data 242
Using AUTO_INCREMENT 243
Performing Additional Queries 244
Preventing SQL Injection 245
Preventing HTML Injection 248
Test Your Knowledge: Questions 250
11. Form Handling . 251
Building Forms 251
Retrieving Submitted Data 253
register_globals: An Old Solution Hangs On 254
Default Values 254
Input Types 256
Text Boxes 256
Text Areas 256
Checkboxes 257
Radio Buttons 259
Hidden Fields 260
Select 260
Labels 262
Sanitizing Input 262
An Example Program 264
Test Your Knowledge: Questions 266
12. Templating with Smarty . 269
Why Smarty? 270
Installation 270
Creating Scripts 271
Creating Templates 272
A Practical Example 272
Test Your Knowledge: Questions 277
13. Cookies, Sessions, and Authentication 279
Using Cookies in PHP 279
Setting a Cookie 281
Accessing a Cookie 281
Destroying a Cookie 282
HTTP Authentication 282
Storing Usernames and Passwords 285
Salting 285
Using Sessions 289
Starting a Session 289
Ending a Session 292
Session Security 293
Test Your Knowledge: Questions 296
14. Exploring JavaScript . 299
JavaScript and HTML Text 299
Using Scripts Within a Document Head 301
Older and Nonstandard Browsers 301
Including JavaScript Files 302
Debugging JavaScript Errors 303
Using Comments 305
Semicolons 305
Variables 306
String Variables 306
Numeric Variables 307
Arrays 307
Operators 308
Arithmetic Operators 308
Assignment Operators 308
Comparison Operators 309
Logical Operators 309
Variable Incrementing and Decrementing 310
String Concatenation 310
Escaping Characters 310
Variable Typing 311
Functions 312
Global Variables 312
Local Variables 312
The Document Object Model 314
Browser Incompatibilities 316
Using the DOM 317
Test Your Knowledge: Questions 318
15. Expressions and Control Flow in JavaScript 319
Expressions 319
Literals and Variables 320
Operators 321
Operator Precedence 321
Associativity 322
Relational Operators 323
The with Statement 325
Using onError 326
Using try .catch 327
Conditionals 328
The if Statement 328
The switch Statement 329
The ? Operator 331
Looping 331
while Loops 331
do .while Loops 332
for Loops 332
Breaking Out of a Loop 333
The continue Statement 334
Explicit Casting 334
Test Your Knowledge: Questions 335
16. JavaScript Functions, Objects, and Arrays . 337
JavaScript Functions 337
Defining a Function 337
Returning a Value 339
Returning an Array 341
JavaScript Objects 341
Declaring a Class 341
Creating an Object 343
Accessing Objects 343
The prototype Keyword 344
JavaScript Arrays 346
Numeric Arrays 346
Associative Arrays 347
Multidimensional Arrays 348
Using Array Methods 349
Test Your Knowledge: Questions 353
17. JavaScript and PHP Validation and Error Handling 355
Validating User Input with JavaScript 355
The validate.html Document (Part One) 356
Regular Expressions 361
Matching Through Metacharacters 361
Fuzzy Character Matching 362
Grouping Through Parentheses 363
Character Classes 363
Indicating a Range 364
Negation 364
Some More Complicated Examples 364
Summary of Metacharacters 367
General Modifiers 369
Using Regular Expressions in JavaScript 369
Using Regular Expressions in PHP 369
Redisplaying a Form After PHP Validation 370
Test Your Knowledge: Questions 375
18. Using Ajax . 377
What Is Ajax? 378
Using XMLHttpRequest 378
Your First Ajax Program 380
Using GET Instead of POST 385
Sending XML Requests 387
Test Your Knowledge: Questions 391
19. Using YUI for Ajax and More 393
Choosing a Framework 393
Using YUI 394
Compressed Versions 396
Using YUI for Ajax 396
Other Uses for YUI 400
A Simple YUI Calendar 401
Test Your Knowledge: Questions 403
20. Bringing It All Together 405
Designing a Social Networking Site 405
About Third-Party Add-Ons 406
On the Website 406
rnfunctions.php 406
The Functions 407
rnheader.php 409
rnsetup.php 410
index.php 411
rnsignup.php 412
rnsignup.php (YUI version) 415
rncheckuser.php 417
rnlogin.php 417
rnprofile.php 419
Adding the “About Me” Text 420
Adding a Profile Image 420
Processing the Image 420
Displaying the Current Profile 421
rnmembers.php 424
Viewing a User’s Profile 424
Adding and Dropping Friends 424
Listing All Members 424
rnfriends.php 427
rnmessages.php 430
rnlogout.php 432
A. Solutions to the Chapter Questions 435
B. Online Resources . 453
C. MySQL’s FULLTEXT Stopwords . 457
D. MySQL Functions 461
E. Using PEAR and PHPUnit . 473
Index . 485
xii |
















Trích Dẫn
Tài liệu này được mua 1 lần.
pe_ng0k