Tải bản đầy đủ (.pdf) (806 trang)

Learning PHP, MySQL javascript, 4th edition

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (14.17 MB, 806 trang )

4t
h

th

beginner's
“This
bookisthata great
introduces 

■■

Learn PHP in-depth, along with the basics of object-oriented
programming

■■

Explore MySQL, from database structure to complex queries

several crucial web
developer languages. 
It's a quick-paced, easyto-read, informationpacked book that will
soon have you creating
dynamically driven websites, including a basic
social networking site.

■■

Use the MySQLi Extension, PHP’s improved MySQL interface

—Albert Wiersch



■■

reate dynamic PHP web pages that tailor themselves to
C
the user

■■

anage cookies and sessions, and maintain a high level
M
of security

■■

Master the JavaScript language—and enhance it with jQuery

■■

Use Ajax calls for background browser/server communication

■■

cquire CSS2 & CSS3 skills for professionally styling your
A
web pages

■■

I mplement all of the new HTML5 features, including

geolocation, audio, video, and the canvas

Explore each technology separately, learn how to use them together, and
pick up valuable web programming practices along the way. At the end of
the book, you’ll put everything together to build a fully functional social
networking site, using XAMPP or any development stack you choose.



developer of CSE HTML Validator

Robin Nixon, an IT journalist who has written hundreds of articles and several
books on computing, has developed numerous websites using open source tools,
specializing in the technologies featured in this book. Robin has worked with and
written about computers since the early 1980s.

US $49.99

Twitter: @oreillymedia
facebook.com/oreilly

Learning

PHP, MySQL
& JavaScript
WITH JQUERY, CSS & HTML5

Nixon

WEB DEVELOPMENT


FOURTH EDITION

Learning PHP,
MySQL & JavaScript

Build interactive, data-driven websites with the potent combination of
open-source technologies and web standards, even if you have only basic
HTML knowledge. With this popular hands-on guide, you’ll tackle dynamic
web programming with the help of today’s core technologies: PHP, MySQL,
JavaScript, jQuery, CSS, and HTML5.

on
iti r y
Ed jQue

wi

Learning PHP, MySQL & JavaScript

CAN $52.99

ISBN: 978-1-491-91866-1

Robin Nixon
www.it-ebooks.info


4t
h


th

beginner's
“This
bookisthata great
introduces 

■■

Learn PHP in-depth, along with the basics of object-oriented
programming

■■

Explore MySQL, from database structure to complex queries

several crucial web
developer languages. 
It's a quick-paced, easyto-read, informationpacked book that will
soon have you creating
dynamically driven websites, including a basic
social networking site.

■■

Use the MySQLi Extension, PHP’s improved MySQL interface

—Albert Wiersch


■■

reate dynamic PHP web pages that tailor themselves to
C
the user

■■

anage cookies and sessions, and maintain a high level
M
of security

■■

Master the JavaScript language—and enhance it with jQuery

■■

Use Ajax calls for background browser/server communication

■■

cquire CSS2 & CSS3 skills for professionally styling your
A
web pages

■■

I mplement all of the new HTML5 features, including
geolocation, audio, video, and the canvas


Explore each technology separately, learn how to use them together, and
pick up valuable web programming practices along the way. At the end of
the book, you’ll put everything together to build a fully functional social
networking site, using XAMPP or any development stack you choose.



developer of CSE HTML Validator

Robin Nixon, an IT journalist who has written hundreds of articles and several
books on computing, has developed numerous websites using open source tools,
specializing in the technologies featured in this book. Robin has worked with and
written about computers since the early 1980s.

US $49.99

Twitter: @oreillymedia
facebook.com/oreilly

Learning

PHP, MySQL
& JavaScript
WITH JQUERY, CSS & HTML5

Nixon

WEB DEVELOPMENT


FOURTH EDITION

Learning PHP,
MySQL & JavaScript

Build interactive, data-driven websites with the potent combination of
open-source technologies and web standards, even if you have only basic
HTML knowledge. With this popular hands-on guide, you’ll tackle dynamic
web programming with the help of today’s core technologies: PHP, MySQL,
JavaScript, jQuery, CSS, and HTML5.

on
iti r y
Ed jQue

wi

Learning PHP, MySQL & JavaScript

CAN $52.99

ISBN: 978-1-491-91866-1

Robin Nixon
www.it-ebooks.info


FOURTH EDITION

Learning PHP, MySQL & JavaScript

With jQuery, CSS & HTML5

Robin Nixon

www.it-ebooks.info


Learning PHP, MySQL & JavaScript
With jQuery, CSS & HTML5
by Robin Nixon
Copyright © 2015 Robin Nixon. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (). For more information, contact our corporate/
institutional sales department: 800-998-9938 or

Editor: Andy Oram
Production Editor: Nicole Shelby
Copyeditor: Rachel Monaghan
Proofreader: Sharon Wilkey
December 2014:

Indexer: Ellen Troutman
Interior Designer: David Futato
Cover Designer: Randy Comer
Illustrator: Rebecca Demarest

Fourth Edition


Revision History for the Fourth Edition
2014-11-21: First Release
See for release details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Learning PHP, MySQL & JavaScript, the
cover image, and related trade dress are trademarks of O’Reilly Media, Inc.
While the publisher and the author have used good faith efforts to ensure that the information and
instructions contained in this work are accurate, the publisher and the author disclaim all responsibility
for errors or omissions, including without limitation responsibility for damages resulting from the use of
or reliance on this work. Use of the information and instructions contained in this work is at your own
risk. If any code samples or other technology this work contains or describes is subject to open source
licenses or the intellectual property rights of others, it is your responsibility to ensure that your use
thereof complies with such licenses and/or rights.

978-1-491-91866-1
[LSI]

www.it-ebooks.info


For Julie

www.it-ebooks.info


www.it-ebooks.info


Table of Contents

Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii

1. Introduction to Dynamic Web Content. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
HTTP and HTML: Berners-Lee’s Basics
The Request/Response Procedure
The Benefits of PHP, MySQL, JavaScript, CSS, and HTML5
Using PHP
Using MySQL
Using JavaScript
Using CSS
And Then There’s HTML5
The Apache Web Server
About Open Source
Bringing It All Together
Questions

2
2
5
6
7
8
9
10
11
12
12
14

2. Setting Up a Development Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
What Is a WAMP, MAMP, or LAMP?
Installing XAMPP on Windows

Testing the Installation
Installing XAMPP on Mac OS X
Accessing the Document Root
Installing a LAMP on Linux
Working Remotely
Logging In
Using FTP
Using a Program Editor
Using an IDE

16
16
24
27
27
28
28
28
29
30
31
v

www.it-ebooks.info


Questions

33


3. Introduction to PHP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Incorporating PHP Within HTML
This Book’s Examples
The Structure of PHP
Using Comments
Basic Syntax
Variables
Operators
Variable Assignment
Multiple-Line Commands
Variable Typing
Constants
Predefined Constants
The Difference Between the echo and print Commands
Functions
Variable Scope
Questions

35
37
38
38
39
40
45
48
50
52
53
54

55
55
56
62

4. Expressions and Control Flow in PHP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Expressions
TRUE or FALSE?
Literals and Variables
Operators
Operator Precedence
Associativity
Relational Operators
Conditionals
The if Statement
The else Statement
The elseif Statement
The switch Statement
The ? Operator
Looping
while Loops
do...while Loops
for Loops
Breaking Out of a Loop
The continue Statement
Implicit and Explicit Casting
PHP Dynamic Linking

vi


|

63
63
65
66
67
69
70
74
75
76
78
79
82
83
84
86
86
88
89
90
91

Table of Contents

www.it-ebooks.info


Dynamic Linking in Action

Questions

92
93

5. PHP Functions and Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
PHP Functions
Defining a Function
Returning a Value
Returning an Array
Do Not Pass Arguments by Reference
Returning Global Variables
Recap of Variable Scope
Including and Requiring Files
The include Statement
Using include_once
Using require and require_once
PHP Version Compatibility
PHP Objects
Terminology
Declaring a Class
Creating an Object
Accessing Objects
Cloning Objects
Constructors
PHP 5 Destructors
Writing Methods
Static Methods in PHP 5
Declaring Properties
Declaring Constants

Property and Method Scope in PHP 5
Static Properties and Methods
Inheritance
Questions

96
98
98
100
100
102
103
103
104
104
105
105
106
106
107
108
109
110
111
112
112
113
114
115
115

116
118
121

6. PHP Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Basic Access
Numerically Indexed Arrays
Associative Arrays
Assignment Using the array Keyword
The foreach...as Loop
Multidimensional Arrays
Using Array Functions
is_array

123
123
125
126
127
129
132
132

Table of Contents

www.it-ebooks.info

|

vii



count
sort
shuffle
explode
extract
compact
reset
end
Questions

132
133
133
133
134
135
136
136
137

7. Practical PHP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Using printf
Precision Setting
String Padding
Using sprintf
Date and Time Functions
Date Constants
Using checkdate

File Handling
Checking Whether a File Exists
Creating a File
Reading from Files
Copying Files
Moving a File
Deleting a File
Updating Files
Locking Files for Multiple Accesses
Reading an Entire File
Uploading Files
System Calls
XHTML or HTML5?
Questions

139
140
142
143
143
146
146
147
147
147
149
150
150
151
151

152
154
155
160
162
162

8. Introduction to MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
MySQL Basics
Summary of Database Terms
Accessing MySQL via the Command Line
Starting the Command-Line Interface
Using the Command-Line Interface
MySQL Commands
Data Types
Indexes

viii

|

Table of Contents

www.it-ebooks.info

165
166
166
167
171

172
177
186


Creating an Index
Querying a MySQL Database
Joining Tables Together
Using Logical Operators
MySQL Functions
Accessing MySQL via phpMyAdmin
Questions

186
192
202
204
204
205
206

9. Mastering MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Database Design
Primary Keys: The Keys to Relational Databases
Normalization
First Normal Form
Second Normal Form
Third Normal Form
When Not to Use Normalization
Relationships

One-to-One
One-to-Many
Many-to-Many
Databases and Anonymity
Transactions
Transaction Storage Engines
Using BEGIN
Using COMMIT
Using ROLLBACK
Using EXPLAIN
Backing Up and Restoring
Using mysqldump
Creating a Backup File
Restoring from a Backup File
Dumping Data in CSV Format
Planning Your Backups
Questions

209
210
211
212
214
217
219
219
219
220
221
222

223
223
224
225
225
226
227
227
229
231
231
232
232

10. Accessing MySQL Using PHP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Querying a MySQL Database with PHP
The Process
Creating a Login File
Connecting to a MySQL Database
A Practical Example
The $_POST Array

233
233
234
235
240
243

Table of Contents


www.it-ebooks.info

|

ix


Deleting a Record
Displaying the Form
Querying the Database
Running the Program
Practical MySQL
Creating a Table
Describing a Table
Dropping a Table
Adding Data
Retrieving Data
Updating Data
Deleting Data
Using AUTO_INCREMENT
Performing Additional Queries
Preventing Hacking Attempts
Steps You Can Take
Using Placeholders
Preventing HTML Injection
Using mysqli Procedurally
Questions

244

245
246
247
248
248
249
250
250
251
251
252
252
254
255
256
257
259
261
263

11. Form Handling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Building Forms
Retrieving Submitted Data
register_globals: An Old Solution Hangs On
Default Values
Input Types
Sanitizing Input
An Example Program
What’s New in HTML5?
The autocomplete Attribute

The autofocus Attribute
The placeholder Attribute
The required Attribute
Override Attributes
The width and height Attributes
Features Awaiting Full Implementation
The form Attribute
The list Attribute
The min and max Attributes
The step Attribute
The color Input Type

x

|

Table of Contents

www.it-ebooks.info

265
267
268
269
270
277
279
281
282
282

282
282
283
283
283
283
284
284
284
285


The number and range Input Types
Date and Time Pickers
Questions

285
285
285

12. Cookies, Sessions, and Authentication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Using Cookies in PHP
Setting a Cookie
Accessing a Cookie
Destroying a Cookie
HTTP Authentication
Storing Usernames and Passwords
Salting
Using Sessions
Starting a Session

Ending a Session
Setting a Time-Out
Session Security
Questions

287
289
290
290
290
294
294
298
299
302
303
303
307

13. Exploring JavaScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
JavaScript and HTML Text
Using Scripts Within a Document Head
Older and Nonstandard Browsers
Including JavaScript Files
Debugging JavaScript Errors
Using Comments
Semicolons
Variables
String Variables
Numeric Variables

Arrays
Operators
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
Variable Incrementing and Decrementing
String Concatenation
Escaping Characters
Variable Typing
Functions
Global Variables

310
311
311
312
313
315
315
316
316
317
317
318
318
318
319
319
320

320
320
321
322
322

Table of Contents

www.it-ebooks.info

|

xi


Local Variables
The Document Object Model
But It’s Not That Simple
Using the DOM
About document.write
Using console.log
Using alert
Writing into Elements
Using document.write
Questions

323
324
326
327

328
328
328
329
329
329

14. Expressions and Control Flow in JavaScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
Expressions
Literals and Variables
Operators
Operator Precedence
Associativity
Relational Operators
The with Statement
Using onerror
Using try...catch
Conditionals
The if Statement
The else Statement
The switch Statement
The ? Operator
Looping
while Loops
do...while Loops
for Loops
Breaking Out of a Loop
The continue Statement
Explicit Casting
Questions


331
332
333
334
334
335
338
339
340
341
341
341
342
344
344
344
345
346
346
347
348
348

15. JavaScript Functions, Objects, and Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
JavaScript Functions
Defining a Function
Returning a Value
Returning an Array
JavaScript Objects

Declaring a Class

xii

|

351
351
353
355
356
356

Table of Contents

www.it-ebooks.info


Creating an Object
Accessing Objects
The prototype Keyword
JavaScript Arrays
Numeric Arrays
Associative Arrays
Multidimensional Arrays
Using Array Methods
Questions

357
358

358
361
361
362
363
364
369

16. JavaScript and PHP Validation and Error Handling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Validating User Input with JavaScript
The validate.html Document (Part 1)
The validate.html Document (Part 2)
Regular Expressions
Matching Through Metacharacters
Fuzzy Character Matching
Grouping Through Parentheses
Character Classes
Indicating a Range
Negation
Some More-Complicated Examples
Summary of Metacharacters
General Modifiers
Using Regular Expressions in JavaScript
Using Regular Expressions in PHP
Redisplaying a Form After PHP Validation
Questions

371
372
374

377
378
378
379
380
380
380
381
383
385
386
386
387
393

17. Using Ajax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
What Is Ajax?
Using XMLHttpRequest
Your First Ajax Program
Using Get Instead of Post
Sending XML Requests
Using Frameworks for Ajax
Questions

395
396
398
403
406
411

411

18. Introduction to CSS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
Importing a Style Sheet
Importing CSS from Within HTML
Embedded Style Settings

414
414
415

Table of Contents

www.it-ebooks.info

|

xiii


Using IDs
Using Classes
Using Semicolons
CSS Rules
Multiple Assignments
Using Comments
Style Types
Default Styles
User Styles
External Style Sheets

Internal Styles
Inline Styles
CSS Selectors
The Type Selector
The Descendant Selector
The Child Selector
The ID Selector
The Class Selector
The Attribute Selector
The Universal Selector
Selecting by Group
The CSS Cascade
Style Sheet Creators
Style Sheet Methods
Style Sheet Selectors
Calculating Specificity
The Difference Between Div and Span Elements
Measurements
Fonts and Typography
font-family
font-style
font-size
font-weight
Managing Text Styles
Decoration
Spacing
Alignment
Transformation
Indenting
CSS Colors

Short Color Strings
Gradients

xiv

|

Table of Contents

www.it-ebooks.info

415
415
416
416
416
417
418
418
418
419
419
420
420
420
420
421
422
423
423

424
425
425
426
426
426
427
429
431
432
433
433
434
434
435
435
435
436
436
436
437
438
438


Positioning Elements
Absolute Positioning
Relative Positioning
Fixed Positioning
Pseudoclasses

Shorthand Rules
The Box Model and Layout
Setting Margins
Applying Borders
Adjusting Padding
Object Contents
Questions

439
440
440
440
442
444
445
445
447
448
450
450

19. Advanced CSS with CSS3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
Attribute Selectors
Matching Parts of Strings
The box-sizing Property
CSS3 Backgrounds
The background-clip Property
The background-origin Property
The background-size Property
Using the auto Value

Multiple Backgrounds
CSS3 Borders
The border-color Property
The border-radius Property
Box Shadows
Element Overflow
Multicolumn Layout
Colors and Opacity
HSL Colors
HSLA Colors
RGB Colors
RGBA Colors
The opacity Property
Text Effects
The text-shadow Property
The text-overflow Property
The word-wrap Property
Web Fonts
Google Web Fonts
Transformations

451
452
453
453
454
456
456
457
457

459
459
459
462
463
463
465
465
466
466
467
467
467
467
468
469
469
470
472

Table of Contents

www.it-ebooks.info

|

xv


3D Transformations

Transitions
Properties to Transition
Transition Duration
Transition Delay
Transition Timing
Shorthand Syntax
Questions

473
474
474
475
475
475
476
477

20. Accessing CSS from JavaScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
Revisiting the getElementById Function
The O function
The S Function
The C Function
Including the Functions
Accessing CSS Properties from JavaScript
Some Common Properties
Other Properties
Inline JavaScript
The this Keyword
Attaching Events to Objects in a Script
Attaching to Other Events

Adding New Elements
Removing Elements
Alternatives to Adding and Removing Elements
Using Interrupts
Using setTimeout
Cancelling a Time-Out
Using setInterval
Using Interrupts for Animation
Questions

479
479
480
481
482
482
483
484
486
486
487
488
489
490
491
492
492
493
493
495

497

21. Introduction to jQuery. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
Why jQuery?
Including jQuery
Choosing the Right Version
Downloading
Using a Content Delivery Network
Always Using the Latest Version
Customizing jQuery
jQuery Syntax
A Simple Example

xvi

|

Table of Contents

www.it-ebooks.info

500
500
500
501
502
503
503
503
504



Avoiding Library Conflict
Selectors
The css Method
The Element Selector
The ID Selector
The Class Selector
Combining Selectors
Handling Events
Waiting Until the Document Is Ready
Event Functions and Properties
The blur and focus Events
The this Keyword
The click and dblclick Events
The keypress Event
Considerate Programming
The mousemove Event
Other Mouse Events
Alternative Mouse Methods
The submit Event
Special Effects
Hiding and Showing
The toggle Method
Fading In and Out
Sliding Elements Up and Down
Animations
Stopping Animations
Manipulating the DOM
The Difference Between The text and html Methods

The val and attr Methods
Adding and Removing Elements
Dynamically Applying Classes
Modifying Dimensions
The width and height Methods
The innerWidth and innerHeight Methods
The outerWidth and OuterHeight Methods
DOM Traversal
Parent Elements
Child Elements
Sibling Elements
Selecting the Next and Previous Elements
Traversing jQuery Selections
The is Method

505
505
506
506
507
507
507
508
509
510
511
512
512
513
515

515
518
519
520
521
522
523
524
525
526
529
530
531
531
533
535
535
536
538
538
539
539
543
543
545
546
548

Table of Contents


www.it-ebooks.info

|

xvii


Using jQuery Without Selectors
The $.each Method
The $.map Method
Using Ajax
Using the Post Method
Using the Get Method
Plug-Ins
The jQuery User Interface
Other Plug-Ins
jQuery Mobile
Questions

549
550
551
551
551
552
553
553
553
554
555


22. Introduction to HTML5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
The Canvas
Geolocation
Audio and Video
Forms
Local Storage
Web Workers
Web Applications
Microdata
Summary
Questions

558
559
561
562
563
563
563
564
564
564

23. The HTML5 Canvas. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565
Creating and Accessing a Canvas
The toDataURL Function
Specifying an Image Type
The fillRect Method
The clearRect Method

The strokeRect Method
Combining These Commands
The createLinearGradient Method
The addColorStop Method in Detail
The createRadialGradient Method
Using Patterns for Fills
Writing Text to the Canvas
The strokeText Method
The textBaseLine Property
The font Property
The textAlign Property
The fillText Method

xviii

|

Table of Contents

www.it-ebooks.info

565
567
569
569
569
570
570
571
573

574
576
578
578
579
579
579
580


The measureText Method
Drawing Lines
The lineWidth Property
The lineCap and lineJoin Properties
The miterLimit Property
Using Paths
The moveTo and LineTo Methods
The stroke Method
The rect Method
Filling Areas
The clip Method
The isPointInPath Method
Working with Curves
The arc Method
The arcTo Method
The quadraticCurveTo Method
The bezierCurveTo Method
Manipulating Images
The drawImage Method
Resizing an Image

Selecting an Image Area
Copying from a Canvas
Adding Shadows
Editing at the Pixel Level
The getImageData Method
The data Array
The putImageData Method
The createImageData Method
Advanced Graphical Effects
The globalCompositeOperation Property
The globalAlpha Property
Transformations
The scale Method
The save and restore Methods
The rotate Method
The translate Method
The transform Method
The setTransform Method
Summary
Questions

581
581
581
581
584
584
584
585
585

586
587
590
591
591
594
595
596
597
597
598
598
600
600
602
602
603
605
605
606
606
609
609
609
610
611
612
613
615
615

616

Table of Contents

www.it-ebooks.info

|

xix


24. HTML5 Audio and Video. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
About Codecs
The <audio> Element
Supporting Non-HTML5 Browsers
The <video> Element
The Video Codecs
Supporting Older Browsers
Summary
Questions

618
619
621
623
623
627
629
629


25. Other HTML5 Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
Geolocation and the GPS Service
Other Location Methods
Geolocation and HTML5
Local Storage
Using Local Storage
The localStorage Object
Web Workers
Offline Web Applications
Drag and Drop
Cross-Document Messaging
Microdata
Other HTML5 Tags
Summary
Questions

631
632
632
636
637
637
639
641
643
645
648
651
652
652


26. Bringing It All Together. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653
Designing a Social Networking Site
On the Website
functions.php
The Functions
header.php
setup.php
index.php
signup.php
Checking for Username Availability
Logging In
checkuser.php
login.php
profile.php
Adding the “About Me” Text
Adding a Profile Image

xx

|

Table of Contents

www.it-ebooks.info

653
654
654
654

656
658
660
661
661
662
665
665
667
668
668


Processing the Image
Displaying the Current Profile
members.php
Viewing a User’s Profile
Adding and Dropping Friends
Listing All Members
friends.php
messages.php
logout.php
styles.css
javascript.js

668
669
672
672
672

672
675
678
681
682
685

A. Solutions to the Chapter Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 687
B. Online Resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 707
C. MySQL’s FULLTEXT Stopwords. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 711
D. MySQL Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715
E. jQuery Selectors, Objects, and Methods. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 747

Table of Contents

www.it-ebooks.info

|

xxi


www.it-ebooks.info


Preface

The combination of PHP and MySQL is the most convenient approach to dynamic,
database-driven web design, holding its own in the face of challenges from integrated

frameworks—such as Ruby on Rails—that are harder to learn. Due to its open source
roots (unlike the competing Microsoft .NET Framework), it is free to implement and
is therefore an extremely popular option for web development.
Any would-be developer on a Unix/Linux or even a Windows/Apache platform will
need to master these technologies. And, combined with the partner technologies of
JavaScript, jQuery, CSS, and HTML5, you will be able to create websites of the caliber
of industry standards like Facebook, Twitter, and Gmail.

Audience
This book is for people who wish to learn how to create effective and dynamic web‐
sites. This may include webmasters or graphic designers who are already creating
static websites but wish to take their skills to the next level, as well as high school and
college students, recent graduates, and self-taught individuals.
In fact, anyone ready to learn the fundamentals behind the Web 2.0 technology
known as Ajax will obtain a thorough grounding in all of these core technologies:
PHP, MySQL, JavaScript, CSS, and HTML5, and learn the basics of the jQuery library
too.

Assumptions This Book Makes
This book assumes that you have a basic understanding of HTML and can at least put
together a simple, static website, but does not assume that you have any prior knowl‐
edge of PHP, MySQL, JavaScript, CSS, or HTML5—although if you do, your progress
through the book will be even quicker.

xxiii

www.it-ebooks.info



×