Index

Symbols

[] (array element operator), 35

-- (decrement operator), 3031

== (equal operator), 3132

$_POST array, 20

$.ajax() method, 508509

$.get() method, 510

$.getJSON() method, 510

$.getscript() method, 510

$.post() method, 510

$this pointer, 164

(backslash), escape sequences, 125126

^ (caret symbol), 121

, (comma operator), 33

@ (error suppression operator), 34

`` (execution operator), 3435

/ (forward slash), 56, 120

% (percent) symbol, printing, 110

& (reference operator), 31

; (semicolon), 16, 222223

() (parentheses), order of precedence, 3738

?: (ternary operator), 34

| (vertical pipe), 123

A

absolute path, 56

abstract classes, 188

access control implementing, 366369

access modifiers, 165, 166

visibility, controlling, 169170

accessing

array contents, 7779

array elements, 79

with each() construct, 8081

with foreach loop, 80

form variables, 2022

assignment operators, 20

htmlspecialchars() function, 2122

PHP, 12

accessor functions, 166168, 178

ACID (atomicity, consistency, isolation, and durability), 317318

add_bms.php, 588589

addClass() method, 498

adding

dynamic content, 1819

locks to files, 7173

addition operator, 28

address field (Bob’s Auto Parts order form), 54

administrator privileges (MySQL), 229

advantages of reusing code

consistency, 132

cost, 132

reliability, 132

aggregating SQL data, 259261

AJAX (Asynchronous JavaScript and XML), 493494

$.ajax() method, 508509

asynchronous requests, 493

helper methods, 509510

$.get(), 510

$.getscript(), 510

$.post(), 510

real-time chat application, building chat server, 504507

aliases

for namespaces, 198

for tables, 257258

ALTER TABLE command (SQL), 265268

altering

error reporting settings, 554556

tables after creation, 265268

alternative control structure syntax, 51

anchoring regular expressions to beginning or end of string, 123

anonymous functions, 155157

Apache

HTTP Server

.htaccess files, 374377

configuring, 356

installing

on UNIX, 600602

on Windows and Mac, 612613

applying

functions to arrray elements, 9798

localization to web pages, 440445

language selector page, 442444

software engineering to web development, 530

templates to web pages, 134139

text to buttons, 461464

arbitrary lengths, reading, 69

ARCHIVE table type, 316

arguments, 39

arithmetic operators, 2829

array elements, 76

accessing, 79

with each() construct, 8081

with foreach loop, 80

applying functions to, 9798

counting, 9899

indices, 76

array key-value pairs for getdate() function, 427428

array operators, 35, 8182

array_count() function, 9899

array_multisort() function, 8788

array_pop() function, 92

array_push() function, 92

array_reverse() function, 92

array_walk() function, 9798

arrays, 24, 7576

$_POST, 20

accessing contents, 7778, 7879

bounding box contents, 463

converting to scalar variables, 99100

initializing, 79

loading from files, 9296

multidimensional arrays, 75, 8285

sorting, 8790

three-dimensional arrays, 8485

two-dimensional arrays, 8284

navigating, 9697

numerically indexed arrays, 7677

reordering, 9091

with shuffle() function, 9091

reversing, 92

sorting, 8587

with asort() function, 8687

with ksort() function, 8687

reverse sorting, 83

with sort() function, 8586

superglobal, 20, 27

asort() function, 8687

assertions, 126127

assigning values to variables, 24

assignment operators, 20

combined assignment operators, 30

values returned from, 29

associativity, 3738

asynchronous requests, 493

atomic column values, 216217

attackers, 339

attributes, 160, 162, 164165, 177

access modifiers, 165, 166

accessor functions, 166168

overriding, 170172

preventing, 172

authentication, 333

access control, 366369

basic authentication, 372377

in PHP, 372373

custom authentication, creating, 377

identifying visitors, 365366

passwords

hash functions, 370371

storing, 369

PHPbookmark project, 569587

changing passwords, 580582

logging in, 576579

logging out, 580

registering users, 569575

resetting forgotten passwords, 582587

in session control, 483491

authmain.php, 483489

logout.php, 490491

members_only.php, 489

authmain.php, 483489

auto_append_file directive, 139140

_autoload() function, 189

AUTO_INCREMENT keyword (MySQL), 234

auto_prepend_file directive, 139140

autocommit mode (MySQL), 318

automatically generated images, 456

available extensions, identifying, 522523

avoiding FTP timeouts, 420

B

backing up

files, 412420

MySQL databases, 310311

backreferences, 126

backtraces, 202

balancing security with usability, 342

bar chart, drawing, 465474

basename() function, 397

basic authentication, 372377

.htaccess files, 374377

in PHP, 372373

basic values, filtering, 346347

basic_auth.php, 372373

Bill Gates Wealth Clock, 407

bitwise operators, 33

blank canvas, creating, 452453

BLOBs (binary large objects), 244

blocks, declaring, 42

Bob’s Auto Parts site

exception handling, 204208

order form

address field, 54

creating, 1214

fields, naming, 14

processing, 14

totals, calculating, 3637

Smart Form Mail application, creating, 101104

bookmark_fns.php, 567568

bookmarks (PHPbookmark project), 561

adding, 588590

deleting, 591594

displaying, 590591

Book-O-Rama bookstore application, 213214

inserting information into database, 282285

results.php, 273275

schema, 221

search form, 272273

Boolean values, 24

bottom-up approach to security, 343

bounding box, 462463

branching, 123

breaking up code, 535536

browsedir2.php, 392

browsedir.php, 390

browsers

cookies, 476, 477

session ID, storing, 477478

setting from PHP, 476477

outputting images to, 455

session control, 475

authentication, 483491

configuring, 482483

sessions

creating, 480482

registering variables, 478479

starting, 478

browsing php.ini file, 355356

Bubbler, 510

built-in functions, 144

buttons

applying text, 461464

creating, 457465

base canvas, setting up, 460461

outputting to browser, 465

positioning text on, 464

text, writing on, 464465

C

calculating

dates

in MySQL, 434435

in PHP, 433434

totals on order forms, 3637

calendar functions, 436

_call method, 188189

callable type, 24

calling

class operations, 165

functions, 19, 141142

recursive functions, 154155

undefined functions, 142143

canvas images

creating, 452453

printing text on, 453454

Cartesian product, 254255

case of strings, changing, 111112

case sensitivity, of identifiers, 239

catch blocks, 200

CHAR type columns, 235

character class, 121122

character sets, 120121, 438440

multi-byte, 438

security implications, 439440

single-byte, 438

characters. See also special characters, 123124

reading, 69

charts, drawing from stored MySQL data, 465474

chat application

chat server, building, 504507

user interface, building, 510517

chat.php, 504507

checkdate() function, 428429

checking

for existence of files, 70

length of strings, 115116

choosing

development environment, 537538

file mode, 55

keys, 217

chop() function, 104

classes, 161

$this pointer, 164

abstract classes, 188

attributes, 162, 164165, 177

converting to strings, 194

designing, 176177

Exception class, 201202

inheritance, 161162, 168169

late static bindings, 186187

multiple inheritance, 172173

preventing, 172

instantiating, 163164

namespaces, 195197

global namespaces, 197198

importing, 198

subnamespaces, 197

naming, 177

ObjectIterator, 192

operations, 162163

calling, 165

polymorphism, 161

structure of, 162163

traits, 174176

writing code for, 177184

accessor functions, 178

metatags, 177

click event, 500

Clifford, John, 510

cloning objects, 187188

closedir() function, 391

closing files, 6365

closures, 155157

code

breaking up, 535536

checking out, 537

for classes, writing, 177184

operations, 181

commenting, 534

debugging, 352353

indenting, 42, 534535

maintainability, 532

optimizing, 540541

organizing, 350351

reusing, 133134

advantages of, 131132

functions, 140157

in large web projects, 531532

require() statement, 134139

traits, 174176

securing, 343

command execution, 353354

escaping output, 348350

filtering input data, 343348

source code, highlighting, 525526

standards, 532

defining naming conventions, 532534

testing, 541542

code blocks, 42

columns, 211, 235237

atomic column values, 216217

data types, 240246

date and time types, 243244

numeric types, 241242

string types, 244246

displaying, 302

indexes, creating, 238

MySQL

CHAR type, 235

VARCHAR type, 235236

primary key, 211

columns_priv table, 296298

combined assignment operators, 30

command line

executing scripts on, 526527

running PHP on, 526527

commands

executing, 353354

MySQL

CREATE INDEX, 238

CREATE TABLE, 232233

CREATE USER, 226

DESCRIBE, 304

EXPLAIN, 304309

GRANT, 226227, 230231

REVOKE, 230, 230231

SHOW, 301304

show tables, 237

use, 232

mysql, 223

SQL

ALTER TABLE, 265268

DELETE, 268

INSERT, 248249

ORDER BY clause, 259

SELECT, 250251, 252253

UPDATE, 265

comments, 1718

comparing

conditionals, 4546

constants and variables, 26

SQL and MySQL, 248

strings, 115

comparison operators, 3132

equal operator, 3132

for WHERE clause, 252253

concatenating strings, 22

conditionals, 41

code blocks, 42

comparing, 4546

else statements, 4243

elseif statements, 4344

if statements, 4142

switch statement, 4445

configuring

Apache HTTP Server, 356

MySQL users, 225232

PHP image support, 449450

session control, 482483

authentication, 483491

connecting

to MySQL, 277278

to network services, interaction failures, 548549

ODBC, 286

constants, 26

error reporting levels, 553554

per-class constants, 185

and variables, 26

constructors, 163

consuming data from other websites, 404408

control structures

alternative syntax, 51

conditionals, 41

code blocks, 42

comparing, 4546

else statements, 4243

elseif statements, 4344

if statements, 4142

switch statement, 4445

declare structure, 5152

repetition structures, 4650

do.while loops, 50

foreach loops, 4950

for loops, 4950

while loops, 4748

stopping, 50

for stored procedures, 323327

declare handlers, 325

controlling visibility, 169170

conversion specification, 109

type codes, 110111

converting

arrays to scalar variables, 99100

classes to strings, 194

dates and times to Unix timestamp, 426

Gregorian to Julian calendar, 436

between PHP and MySQL date formats, 431433

cookies, 476, 477

session ID, 476

setting from PHP, 476477

correlated subqueries, 264

count() function, 93, 9899

counted subexpressions, 123

counting array elements, 9899

crackers, 339

CREATE INDEX command, 238

CREATE TABLE command, 232233

CREATE USER command, 226

creating

Bob’s Auto Parts order form, 1214

buttons

base canvas, setting up, 460461

outputting to browser, 465

text, applying, 461464

text, positioning, 464

column indexes, 238

directories, 394

files, 398

HTML elements, 497498

images, 451455

make_button.php, 458460

MySQL tables, 232234

MySQL users, 224

sessions, 480482

cross joins, 258

crypt() function, 370

CSV table type, 316

current() function, 9697

cursors, 323, 325

custom authentication, creating, 377

customer feedback form (Bob’s Auto Parts site), creating, 101104

customer order form

address field, 54

creating, 1214

fields, naming, 14

processing, 14

totals, calculating, 3637

D

data hiding, 160

data storage, RDBMSs, 74

data types, 2425

for MySQL columns, 240246

date and time types, 243244

numeric types, 241242

string types, 244246

scalar values, 26

type casting, 25

type strength, 25

databases. See also RDBMSs (relational database management systems)

advantages of, 209

designing, 213220

dropping, 268269

MySQL, 209

backing up, 310311

chat server, building, 504507

DATE_FORMAT() function, 431432

dates, calculating, 434435

displaying, 302

inserting data, 282285

interaction failures, 547548

restoring, 311

security, 299301

UNIX_TIMESTAMP() function, 432433

users, setting up, 225232

null values, 217218

ODBC, 286

optimizing, 309310

design optimization, 309

table optimization, 310

PHPbookmark project, implementing, 565566

querying, 278

RDBMSs, 74

replication, 311313

initial data transfer, performing, 313

master, setting up, 312313

slaves, setting up, 313

schemas, 212

security, 357359

transactions, 317319

update anomalies, 215

web database architecture, 218220, 272

Date, C.J., 220

date and time type columns, 243244

date() function, 18, 1920, 424427

format codes, 424425

Unix timestamps, 426427

DATE_FORMAT() function, 431432

dates

calculating

in MySQL, 434435

in PHP, 433434

calendar functions, 436

converting between PHP and MySQL formats, 431433

Gregorian dates, 436

Julian dates, 436

validating with checkdate() function, 428429

db table, 295296

DDL (Data Definition Language), 248

debugging, 352353

variables, 551553

declare handlers, 325

declare structure, 5152

declaring

blocks, 42

constants, 26

functions, 144

decrement operators, 3031

define() function, 26

defining naming conventions for large projects, 532534

DELETE command (SQL), 268

delete_bms.php, 592593

deleting

bookmarks, 591594

files, 70, 398

records from database, 268

deletion anomalies, 215

delimiters, 120

denial of service, 335337, 361

descenders, 463

DESCRIBE command, 304

designing

classes, 176177

RDBMSs, 213220

destroying

image identifiers, 455

sessions, 479

destructors, 163

die() function, 520522

directories

creating, 394

reading from, 390393

retrieving information, 394

submission form, 408

directory structure for large projects, 536

directory_submit.php, 409412

disaster planning, 362364

disconnecting from MySQL database, 281

disgruntled employees, threats posed by, 339

displaying

bookmarks, 590591

columns, 302

databases, 302

MySQL privileges, 302

tables, 237

division operator, 28

DML (Data Manipulation Language), 248

DMZs (demilitarized zones), 360361

documentation

function libraries, 536

PHP manual, 531

project documentation, 538

dot notation, 255

double-quoted strings, interpolation, 22

do.while loops, 50

drawing bar charts, 465474

dropping

databases, 268269

tables, 268

DSN (data source name), 288

dump_array() function, 552553

dump_variables.php, 551553

dynamic content, adding, 1819

E

each() construct, accessing array contents, 8081

each() function, 80

echo statement, 22

else statements, 4243

elseif statements, 4344

email, sending and reading, 404

embedding PHP in HTML, 1419

comments, 1718

statements, 16

tags, 16

whitespace, 17

empty() function, 40

encapsulation, 160

end() function, 9697

environment variables, 401402

equal operator, 3132

equi-joins, 258

error handling, 208

error reporting levels, 553554

logging errors, 560

graceful error logging, 557559

logic errors, 549551

opening files, 5861

programming errors, 543551

runtime errors, 544549

causes of, 545549

syntax errors, 543544

triggering your own errors, 556

error messages for undefined functions, 142143

error reporting levels, 553554

error reporting settings, altering, 554556

error suppression operator, 34, 60

escape sequences, 125126

escapeshellcmd() function, 354

escaping

from HTML, 16

output, 348350

eval() function, 519520

evaluating

SELECT queries, 304309

strings, 519520

event handling

jQuery, 499504

click event, 500

focusout event, 503

on() method, 499500

ready event, 499

submit event, 504

triggers, 327329

Exception class, 201202

exception handling, 199201, 557

in Bob’s Auto Parts site, 204208

catch blocks, 200

Exception class, 201202

finally blocks, 200

throw keyword, 200

try blocks, 199

user-defined exceptions, 202204

executing commands, 353354

execution directives, 5152

execution operator, 3435

existence of files, checking for, 70

exit() function, 520522

EXPLAIN command, 304309

explode() function, 9596

splitting strings with, 112113

extensions

loaded extensions, identifying, 522523

PDO data access abstraction extension, 286289

php_gd2.dll extension, registering, 450

extract() function, 99100

F

fclose() function, 6365

feedback form (Bob’s Auto Parts site), creating, 101104

feof() function, 6667

fgetc() function, 69

fgetcsv() function, 6768

fgets() function, 6768

fgetts() function, 6768

fields, naming, 14

file formats, 6263

file() function, 6869, 93

file mode, 55

choosing, 55

fopen() function, 57

file systems

absolute path, 56

file information, retrieving, 395397

relative path, 56

security, 352

file_exists() function, 70

file_get_contents() function, 6869

file_put_contents() function, 61

fileatime() function, 397

filedetails.php, 395396

fileowner() function, 397

fileperms() function, 397

files

.htaccess files, 374377

backing up, 412420

characters, reading, 69

closing, 6365

creating, 398

deleting, 70, 398

existence of, checking for, 70

flat files, 5354

problems with, 73

image files

creating, 451455

GIFs, 451

JPEGs, 450

PNGs, 450451

loading arrays from, 9296

locking, 7173

logging errors to, 560

moving, 398

navigating inside, 7071

opening, 55

error handling, 5861

with fopen() function, 5658

through FTP or HTTP, 58

in PHPbookmark application, 564565

processing, 55

properties, changing, 397398

reading from, 55, 6566, 6768, 6869

as cause for runtime errors, 546547

line-by-line, 6768

require() statement, 132134

size of, determining, 70

uploading, 379389, 420

HTML form, 381382

php.ini settings, 380381

tracking upload progress, 387388

troubleshooting, 389

writing the file handling script, 382387

writing to, 55, 61

filesize() function, 70, 397

filtering

input data, 276, 343348

basic values, 346347

double-checking expected values, 344346

strings, 347348

strings, 105107

for output to browser, 105106

for output to email, 106107

final keyword, 172

finally blocks, 200

finding

non-matching rows, 256257

strings within strings, 116117

substrings with regular expressions, 128129

firewalls, 360

flat files, 5354

problems with, 73

float data type, 25

floating-point types, 242

floatval() function, 41

flock() function, 7173

focusout event, 503

fonts, TrueType, 457

fopen() function, 55, 66

file mode, 57

opening files with, 5658

parameters, 56

foreach loops, 4950, 190

accessing array elements, 80

FOREIGN KEY keyword (MySQL), 235

foreign keys, 212, 319

Book-O-Rama bookstore application, 221

forgot_passwd.php, 583584

format codes, date() function, 424425

formatting

strings

changing case of, 111112

conversion specification, 109

for printing, 109111

timestamps, 429431

forms

Book-O-Rama bookstore application

HTML form, 282285

search form, 272273

customer order form

creating, 1214

fields, naming, 14

processing, 14

Smart Form Mail application

creating, 101104

regular expressions, 127128

submission form, 408

variables, accessing, 2022

fpassthru() function, 6869

fputs() function, 61

fread() function, 69

front end interface, building for chat application, 504507

fseek() function, 7071

ftell() function, 7071

FTP

avoiding timeouts, 420

backing up files with, 412420

files, opening, 58

ftp_mirror.php, 413416

ftp_nlist() function, 421

ftp_size() function, 420

full joins, 254255

func_num_args() function, 148

functions, 140

_autoload(), 189

_get(), 166168

_set(), 166168

accessor functions, 166168, 178

aggregate functions (MySQL), 259261

applying to array elements, 9798

arguments, 39

array_count(), 9899

array_multisort(), 8788

array_pop(), 92

array_push(), 92

array_reverse(), 92

array_walk(), 9798

asort(), 8687

backtraces, 202

basename(), 397

built-in, 144

calling, 19, 141142

case functions, 112

case sensitivity, 143

checkdate(), 428429

chop(), 104

closedir(), 391

closures, 155157

count(), 93, 9899

crypt(), 370

current(), 9697

date(), 18, 1920, 424427

format codes, 424425

DATE_FORMAT(), 431432

define(), 26

die(), 520522

dump_array(), 552553

each(), 80

empty(), 40

end(), 9697

escapeshellcmd(), 354

eval(), 519520

exit(), 520522

explode(), 9596

splitting strings with, 112113

extract(), 99100

fclose(), 6365

feof(), 6667

fgetc(), 69

fgetcsv(), 6768

fgets(), 6768

fgetts(), 6768

file(), 6869, 93

file_exists(), 70

file_get_contents(), 6869

file_put_contents(), 61

fileatime(), 397

fileowner(), 397

fileperms(), 397

filesize(), 70, 397

floatval(), 41

flock(), 7173

fopen(), 55, 66

file mode, 57

opening files with, 5658

parameters, 56

fpassthru(), 6869

fputs(), 61

fread(), 69

fseek(), 7071

ftell(), 7071

ftp_nlist(), 421

ftp_size(), 420

func_num_args(), 148

fwrite(), 61

parameters, 62

get_loaded_extensions(), 523

getdate(), 427428

array key-value pairs, 427428

getenv(), 401402

getlastmod(), 524

gettext(), 444448

gettype(), 39

header(), 455

highlight_string(), 525

htmlspecialchars(), 2122, 105106

imagecolorallocate(), 453

imagecreatetruecolor(), 452453

imagecreatfrompng(), 461

imagefill(), 453454

imagefilledrectangle(), 472

imageline(), 472

imagestring(), 454

imagettftext(), 462

implode(), 113

ini_get(), 524525

ini_set(), 524

intval(), 41

isset(), 40, 152

join(), 113

krsort(), 83

ksort(), 8687

libraries, 536

lookup functions, 408412

ltrim(), 104

mail(), 104, 404

microtime(), 435

mkdir(), 394

mktime(), 426427

multibyte string functions, 440

mysqli(), 547

namespaces, 195197

global namespaces, 197198

importing, 198

subnamespaces, 197

naming, 145146

next(), 9697

nl2br(), 70, 107109

nonexistent, as cause for runtime errors, 545546

number_format(), 37

in ObjectIterator class, 192

opendir(), 391

overloading, 145

parameters, 146148

passing, 141

passing by reference, 150151

passthru(), 399

phpinfo(), 26, 141

pollServer(), 515516

pos(), 9697

preg_match(), 128129

preg_split(), 129130

prev(), 9697

printf(), 109111

program execution, 398401

prototype, 141142

putenv(), 401402

range(), 77

readdir(), 391

readfile(), 6869

recursive, 154155

reset(), 9697

return keyword, 152153

returning values from, 153

rewind(), 7071

rmdir(), 394

rsort(), 83

scope, 148150

serialize(), 521

session_start(), 478

set_error_handler(), 557558

setcookie(), 476

settype(), 39

show_source(), 525

shuffle(), 9091

sizeof(), 9899

sort(), 76, 8586

sprintf(), 109

str_replace(), 107, 118119

strcasecmp(), 115

strchr(), 117

strcmp(), 115

strftime(), 429431

stristr(), 117

strnatcmp(), 115

strpos(), 117118

strstr(), 116117

strtok(), 113114

strtolower(), 112

strtoupper(), 112

structure of, 144145

strval(), 41

substr(), 114

system(), 399

trigger_error(), 556

trim(), 104

uasort(), 89

ucfirst(), 112

ucwords(), 112

uksort(), 89

umask(), 394

undefined functions, calling, 142143

UNIX_TIMESTAMP(), 432433

unlink(), 70

unserialize(), 521

urlencode(), 407

user-defined, 144

usort(), 8889

variable functions, 146

variable handling functions, 3940

vprintf(), 111

vsprintf(), 111

fwrite() function, 61

parameters, 62

G

GD2 image library, 449

generating

bar charts from stored MySQL data, 465474

charts from stored MySQL data, 465474

generators, 192193

_get() function, 166168

get_loaded_extensions() function, 523

getdate() function, 427428

array key-value pairs, 427428

getenv() function, 401402

getlastmod() function, 524

gettext() function, 444448, 446

gettype() function, 39

GIF (Graphics Interchange Format) files, 451

Git, 537

global keyword, 150

global namespaces, 197198

GNU gettext

installing, 444445

translation files, 445447

graceful error logging, 557559

GRANT command, 226227, 230231

grant tables, 291299

columns_priv table, 296298

connection verification, 298

db table, 295296

procs_priv table, 296298

request verification, 298

tables_priv table, 296298

user table, 293295

Greenspun, Philip, 407

Gregorian dates, 436

grouping SQL data, 259261

H

handle.php, 558

handles, 161

hash functions, 370371

header() function, 455

headers, 438439

locale-specific, 441442

helper methods, 509510

$.get(), 510

$.getJSON(), 510

$.getscript(), 510

$.post(), 510

heredoc syntax, 23

highlight_string() function, 525

highlighting source code, 525526

hosting providers, 599600

HTML

Book-O-Rama form, 282285

elements

creating, 497498

selecting with jQuery selectors, 496497

escaping, 16

file upload form, 381382

PHP, embedding, 1419, 16

comments, 1718

statements, 16

whitespace, 17

reusing, applying templates to web pages, 134139

submission form, 408

htmlspecialchars() function, 2122, 105106

HTTP files, opening, 58

I

identifiers, 2324, 239240

case sensitivity, 239

rules, 239

identifying script owner, 523

IETF (Internet Engineering Task Force), 404

if statements, 4142

image identifiers, destroying, 455

imagecolorallocate() function, 453

imagecreatetruecolor() function, 452453

imagecreatfrompng() function, 461

imagefill() function, 453454

imagefilledrectangle() function, 472

imageline() function, 472

ImageMagick image library, 449

images

automatically generated, 456

bar chart, drawing from stored SQL data, 465474

buttons

creating, 457465

outputting to browser, 465

positioning text on, 464

text, applying, 461464

writing text on, 464465

canvas images

creating, 452453

printing text on, 453454

creating, 451455

make_button.php, 458460

GIFs, 451

JPEGs, 450

libraries, 449

outputting to browser, 455

php_gd2.dll extension, registering, 450

PNGs, 450451

simplegraph.php, 451452

support in PHP, configuring, 449450

imagestring() function, 454

imagettftext() function, 462

IMAP4 (Internet Message Access protocol), 404

implode() function, 113

importing namespaces, 198

increment operators, 3031

indenting code, 42

indexes, creating, 310

indices, 76

numerically indexed arrays, 7677

inheritance, 161162, 168169

late static bindings, 186187

multiple inheritance, 172173

overriding, 170172

preventing, 172

ini_get() function, 524525

ini_set() function, 524

initializing arrays, 79

numerically indexed arrays, 7677

inner joins, 258

InnoDB table type, 316

transactions, 318319

input data, filtering, 343348

basic values, 346347

double-checking expected values, 344346

strings, 347348

INSERT command (SQL), 248249

inserting data into SQL database, 248250, 282285

insertion anomalies, 215

installing

Apache

on UNIX, 600602

on Windows and Mac, 612613

GNU gettext, 444445

MySQL on UNIX, 602605

PEAR, 613614

PHP

with other web servers, 614

on UNIX, 605609

on Windows and Mac, 612613

instanceof operator, 35, 185186

instantiating classes, 163164

integers, 25

integral data types, 241

interacting with the environment, 401402

interfaces, 173174

Book-O-Rama HTML form, 282285

Iterator, 190191

PDO data access abstraction extension, 286289

internationalization, 437438

applying to web pages, 440445

language selector page, 442444

locale-specific headers, 441442

gettext() function, 444448

GNU gettext, installing, 444445

translation files, 445447

interpolation, 22

intval() function, 41

isset() function, 40, 152

iteration, 4650, 190192

accessing array contents, 7879

do.while loops, 50

foreach loops, 4950

for loops, 4950

while loops, 4748

Iterator interface, 190191

J

JavaScript. See also AJAX; jQuery

AJAX, 493494

join() function, 113

joining strings, 113

joins

cross joins, 258

equi-joins, 258

full joins, 254255

inner joins, 258

joining more than two tables, 255256

left joins, 256257

JPEG (Joint Photographic Experts Group) files, 450

jQuery, 494504

$.ajax() method, 508509

addClass() method, 498

AJAX helper methods, 509510

$.get(), 510

$.getJSON(), 510

$.getscript(), 510

$.post(), 510

events, 499504

click event, 500

focusout, 503

on() method, 499500

ready event, 499

submit, 504

namespace, 495

pseudo-selectors, 497

selectors, 495498

acting on, 498

syntax, 496497

selectors (jQuery), creating HTML elements, 497498

val() method, 498

in web applications, 494495

Julian dates, 436

K

keys, 76, 211212

Book-O-Rama bookstore application, 221

choosing, 217

foreign keys, 212, 319

success, 507

keywords

clone, 187188

final, 172

global, 150

MySQL

AUTO_INCREMENT, 234

FOREIGN KEY, 235

NOT NULL, 234

PRIMARY KEY, 234235

return, 152153

static, 185

throw, 200

trait, 174176

yield, 192193

krsort() function, 83

ksort() function, 8687

L

languages

headers, 438439

multi-byte, 438

single-byte, 438

large web application projects, 529

choosing a development environment, 537538

coding standards, 532

breaking up code, 535536

commenting your code, 534

defining naming conventions, 532534

indenting, 534535

directory structure, 536

documenting, 538

function libraries, 536

optimizing code, 540541

prototyping, 538539

reusing code, 531532

separating logic from content, 539540

testing code, 541542

version control, 536537

writing maintainable code, 532

late static bindings, 186187

left joins, 256257

length of strings, checking, 115116

libraries

function libraries, 536

image libraries, 449

jQuery library, loading, 494495

LIMIT clause (SELECT command), 261262

line-by-line reading from files, 6768

linking tables, 218

list() construct, 81

list_functions.php, 522523

literals, 23

LOAD DATA INFILE statement, 315

loaded extensions, identifying, 522523

loading

arrays from files, 9296

files with require() statement, 132134

jQuery library, 494495

local variables, 323

locales, 438

localization, 437438

applying to web pages, 440445

language selector page, 442444

character sets, 438440

multi-byte, 438

security implications, 439440

single-byte, 438

gettext() function, 444448

GNU gettext, installing, 444445

translation files, 445447

headers, 438439

locale-specific, 441442

locales, 438

multibyte string functions, 440

locking files, 7173

logging errors

graceful error logging, 557559

to log file, 560

logging in to MySQL, 223224

logic, separating from content, 539540

logic errors, 549551

logical operators, 3233

login.php, 566567

logout.php, 490491

lookup functions, 408412

lookup.php, 405

for loops, 4950

loops

accessing array contents, 7879

do.while loops, 50

foreach loops, 4950, 190

for loops, 4950

while loops, 4748

ltrim() function, 104

M

Mac OS, installation packages, 612613

mail() function, 104, 404

maintainability of code, 532

make_button.php, 458460

many-to-many relationships, 213

master, setting up for replication, 312313

matching

special characters, 123124

substrings with string functions, 116

max_execution_time directive, 524

member.php, 576577

members_only.php, 489

MEMORY table type, 316

Mercurial, 537

MERGE table type, 316

meta characters, 124125

metatags, 177

on() method, 499500

methods

$.ajax(), 508509

AJAX helper methods, 509510

$.get(), 510

$.getJSON(), 510

$.getscript(), 510

$.post(), 510

in Exception class, 201202

jQuery

on(), 499500

addClass(), 498

val(), 498

overloading, 188189

static, 185

microseconds, 435

microtime() function, 435

mirroring files, 412420

mkdir() function, 394

mktime() function, 426427

modification anomalies, 215

modification date of scripts, obtaining, 523524

modulus operator, 28

monitoring security, 342343

moving files, 398

multibyte string functions, 440

multidimensional arrays, 75, 8285

sorting, 8790

with array_multisort() function, 8788

reverse sorting, 8990

user-defined sorts, 8889

three-dimensional arrays, 8485

two-dimensional arrays, 8284

multiline comments, 17

multiple inheritance, 172173

multiplication operator, 28

MyISAM storage engine, 316

MySQL, 209, 221222. See also MySQL monitor

aggregating data, 259261

autocommit mode, 318

chat server, building, 504507

columns

data types, 240246

date and time types, 243244

indexes, creating, 238

numeric types, 241242

string types, 244246

commands

AUTO_INCREMENT keyword, 234

CREATE USER, 226

DESCRIBE, 304

EXPLAIN, 304309

FOREIGN KEY keyword, 235

GRANT, 226227, 230231

mysql, 223

NOT NULL keyword, 234

PRIMARY KEY keyword, 234235

REVOKE, 230231

SHOW, 301304

SHOW command, 303304

databases

backing up, 310311

creating, 224

restoring, 311

selecting, 232

date format, converting to PHP, 431433

DATE_FORMAT() function, 431432

dates, calculating, 434435

drawing charts from stored data, 465474

identifiers, 239240

case sensitivity, 239

rules, 239

installing

on UNIX, 602605

on Windows and Mac, 612613

joins

cross joins, 258

equi-joins, 258

full joins, 254255

inner joins, 258

joining more than two tables, 255256

left joins, 256257

logging in, 223224

optimizing databases, 309310

design optimization, 309

table optimization, 310

privileges, 291299

columns_priv table, 296298

db table, 295296

displaying, 302

procs_priv table, 296298

tables_priv table, 296298

updating, 299

user table, 293295

querying from the Web, 275281

disconnecting from database, 281

filtering input data, 276

prepared statements, 279280

retrieving the results, 280281

selecting the database, 278

setting up connection, 277278

runtime errors, 547548

security, 299301

passwords, 300

web issues, 301

stored procedures, 320327

control structures, 323327

cursors, 323, 325

declare handlers, 325

example of, 320323

local variables, 323

tables

aliases, 257258

altering after creation, 265268

columns, 235237

creating, 232234

dropping, 268

viewing, 237238

UNIX_TIMESTAMP() function, 432433

user privileges, 300301

users, 225232

creating, 224

principle of least privilege, 225

privileges, 225231, 227230

web access, 231232

mysql command, 223

MySQL monitor, 222223

mysqli() function, 547

mysqli library, 277

prepared statements, 279280

N

namespaces, 195197

aliasing, 198

global namespaces, 197198

importing, 198

jQuery, 495

subnamespaces, 197

naming

classes, 177

fields, 14

functions, 145146

tables, 257258

navigating

within arrays, 9697

inside files, 7071

network security, 360361

denial of service attacks, 361

DMZ, 360361

firewalls, 360

network services, interaction failures, 548549

next() function, 9697

Nginx servers, 614

nl2br() function, 70, 107109

nonexistent functions, as cause for runtime errors, 545546

non-matching rows, finding, 256257

NOT NULL keyword (MySQL), 234

NOT operator, 3233

NULL type, 24

null values, 217218

number_format() function, 37

numeric type columns, 241242

floating-point types, 242

integral data types, 241

numerically indexed arrays, 7677

O

ObjectIterator class, 192

objects, 24, 160, 161

classes, 161

cloning, 187188

instantiating a class, 163164

interfaces, 160, 173174

serializing, 521

ODBC (Open Database Connectivity), 286

one-to-many relationships, 213

one-to-one relationships, 213

one-way hash functions, 370

OO (object-oriented) development, 159

_autoload() function, 189

accessor functions, 166168

attributes, 160

overriding, 170172

classes, 161

abstract classes, 188

attributes, 162, 164165, 177

constructors, 163

converting to strings, 194

designing, 176177

destructors, 163

Exception class, 201202

instantiating, 163164

ObjectIterator, 192

operations, 162163

structure of, 162163

writing code for, 177184

encapsulation, 160

generators, 192193

inheritance, 161162, 168169

multiple inheritance, 172173

preventing, 172

instanceof operator, 185186

interfaces, 173174

Iterator, 190191

iteration, 190192

late static bindings, 186187

namespaces, 195197

global namespaces, 197198

importing, 198

subnamespaces, 197

objects, 160, 161

cloning, 187188

serializing, 521

operations, 160

calling, 165

per-class constants, 185

polymorphism, 161

reflection API, 194195

static methods, 185

traits, 174176

type hinting, 185186

opendir() function, 391

opening files, 55

error handling, 5861

with fopen() function, 5658

through FTP or HTTP, 58

operands, 28

operating system, securing, 361362

operations, 160, 162163, 181

calling, 165

constructors, 163

destructors, 163

overriding, 170172

preventing, 172

AND operator, 3233

OR operator, 3233

operators, 28

arithmetic operators, 2829

array operators, 35, 8182

assignment operators, 20, 2931

combined assignment operators, 30

values returned from, 29

associativity, 3738

bitwise operators, 33

comparison operators, 3132

equal operator, 3132

decrement operators, 3031

error suppression operator, 34, 60

execution operator, 3435

increment operators, 3031

instanceof, 185186

logical operators, 3233

precedence, 3738

reference operator, 31

string concatenation operator, 22

string operators, 29

for subqueries, 263

ternary operator, 34

type operator, 35

optimizing

code, 540541

databases, 309310

design optimization, 309

table optimization, 310

options for session configuration, 482483

ORDER BY clause, 259

order forms

address field, 54

creating, 1214

fields, naming, 14

processing, 14

storing and retrieving orders, 54

strings, 115

totals, calculating, 3637

organizing code, 350351

outputting

buttons to browser, 465

images, 455

overloading methods, 188189

overriding, 170172

preventing, 172

owner of scripts, identifying, 523

P

parameters, 146148

extract() function, 100

fopen() function, 56

fwrite() function, 62

htmlspecialchars() function, 105106

passing, 141

parser errors, 543544

passing by reference, 150151

passing by value, 150151

passing parameters, 141

passthru() function, 399

passwords, 369371

hash functions, 370371

MySQL, 300

storing, 369

pattern matching, delimiters, 120

PEAR (PHP Extension and Application Repository), installing, 613614

per-class constants, 185

performance, optimizing databases

design optimization, 309

table optimization, 310

permissions, 59

PHP

accessing, 12

basic authentication, 372373

dates, calculating, 433434

embedding in HTML, 1419

comments, 1718

tags, 16

whitespace, 17

English language manual, 531

environment information, obtaining, 522

installing

with other web servers, 614

on UNIX, 605609

on Windows and Mac, 612613

statements, 16

tags

short style, 16

XML style, 16

PHP interpreter, 600

php_gd2.dll extension, registering, 450

PHPbookmark project, 561

add_bms.php, 588589

basic site, implementing, 566569

bookmark_fns.php, 567568

bookmarks

adding, 588590

deleting, 591594

displaying, 590591

database, implementing, 565566

delete_bms.php, 592593

files, 564565

forgot_passwd.php, 583584

implementing recommendations, 594597

login.php, 566567

member.php, 576577

recommend.php, 595597

register_form.php, 569570

register_new.php, 570572

solution components, 561565

user authentication, 569587

changing passwords, 580582

logging in, 576579

logging out, 580

registering users, 569575

resetting forgotten passwords, 582587

phpinfo() function, 26, 141

php.ini file

browsing, 355356

date.timezone setting, 424

file upload settings, 380381

session upload progress configuration settings, 387

planning web application projects, 530531

PNG (Portable Network Graphics) files, 450451

PO (Portable Object) files, 445446

Poedit, 446

pollServer() function, 515516

polymorphism, 161

POP (Post Office Protocol), 404

pos() function, 9697

position of substrings, identifying, 117118

positioning text on buttons, 464

POSIX-style regular expressions, 119

precedence, 3738

preg_match() function, 128129

preg_split() function, 129130

prepared statements, 279280

Pressman, Roger, 542

prev() function, 9697

preventing inheritance, 172

primary key, 211

PRIMARY KEY keyword (MySQL), 234235

primary keys, Book-O-Rama bookstore application, 221

principle of least privilege, 225

printf() function, 109111

printing

echo statement, 22

formatting strings for, 109111

percent symbol, 110

text on canvas images, 453454

private access modifier, 166

visibility, controlling, 169170

privileges (MySQL), 225231, 227230, 291299, 300301

administrator privileges, 229

columns_priv table, 296298

CREATE USER command, 226

db table, 295296

displaying, 302

GRANT command, 226227

principle of least privilege, 225

procs_priv table, 296298

revoking, 230

special privileges, 230

tables_priv table, 296298

updating, 299

user privileges, 228

user table, 293295

processfeedback_v2.php, 108109

processing

customer order form, 14

files, 55

processorder.php, 1419

creating, 14

dynamic content, adding, 1819

with exception handling, 205208

form variables, accessing, 2022

functions, calling, 19

procs_priv table, 296298

progex.php, 400401

program execution functions, 398401

programming errors, 543551

logic errors, 549551

runtime errors, 544549

causes of, 545549

syntax errors, 543544

properties of files, changing, 397398

protected access modifier, 166

protecting multiple web pages, 371

protocols, 403404

prototype, 141142

prototyping web applications, 538539

pseudo-selectors, 497

public access modifier, 166

visibility, controlling, 169170

putenv() function, 401402

Q

querying databases

SELECT queries, evaluating, 304309

subqueries, 262263

correlated subqueries, 264

operators, 263

row subqueries, 264

as temporary table, 264

from the Web, 275281

disconnecting from database, 281

filtering input data, 276

prepared statements, 279280

retrieving the results, 280281

selecting the database, 278

setting up connection, 277278

R

range() function, 77

RDBMSs (relational database management systems), 74

atomic column values, 216217

columns, 211

design principles, 213220

keys, 211212

choosing, 217

MySQL

databases, creating, 224

databases, selecting, 232

logging in, 223224

mysql command, 223

privileges, 225231

tables, creating, 232234

users, creating, 224

null values, 217218

relationships, 213

rows, 211

schemas, 212

tables, 210, 218

update anomalies, 215

values, 211

readdir() function, 391

readfile() function, 6869

reading

arbitrary lengths, 69

characters, 69

email, 404

from files, 55, 6566, 6768, 6869

as cause for runtime errors, 546547

line-by-line, 6768

form directories, 390393

ready event, 499

real-time chat application, chat server, building, 504507

recommend.php, 595597

records

deleting, 268

storing, 62

updating, 265

recursive functions, 154155

reducing web application security risks

access to sensitive data, 332333

denial of service, 336337

loss of data, 334335

malicious code injection, 337

reference operator, 31

reflection API, 194195

register_form.php, 569570

register_new.php, 570572

registering

php_gd2.dll extension, 450

session variables, 478479

regular expressions, 119130

anchoring to beginning or end of string, 123

assertions, 126127

backreferences, 126

branching, 123

character class, 121122

character sets, 120121

counted subexpressions, 123

delimiters, 120

escape sequences, 125126

meta characters, 124125

POSIX, 119

repetition, 122

in Smart Form Mail application, 127128

special characters, matching, 123124

strings, splitting, 129130

substrings, finding, 128129

substrings, replacing, 129

relationships, 213

relative path, 56

reordering arrays, 9091

with shuffle() function, 9091

repetition in regular expressions, 122

repetition structures, 4650

accessing array contents, 7879

do.while loops, 50

foreach loops, 4950

for loops, 4950

while loops, 4748

replacing substrings

with regular expressions, 129

with string functions, 116

replication, 311313

initial data transfer, performing, 313

master, setting up, 312313

slaves, setting up, 313

repudiation, 338339

require() statement, 132134

adding templates to web pages, 134139

reset() function, 9697

resource type, 24

restoring MySQL databases, 311

results.php, 273275

querying from the Web, filtering input data, 276

retrieving data from SQL databases, 250259

criteria, specifying, 251253

joining more than two tables, 255256

from multiple tables, 253258

finding rows that don’t match, 256257

full joins, 254255

ORDER BY clause, 259

SELECT command, 250251

return keyword, 152153

returning values from functions, 153

reusing code

advantages of, 131132

consistency, 132

cost, 132

reliability, 132

functions, 140

built-in functions, 144

calling, 141142

case sensitivity, 143

closures, 155157

naming, 145146

parameters, 146148

parameters, passing, 141

prototype, 141142

recursive functions, 154155

return keyword, 152153

returning values from, 153

scope, 148150

structure of, 144145

undefined functions, calling, 142143

user-defined, 144

variable functions, 146

in large web projects, 531532

maintainability, 532

require() statement, 132134

applying templates to web pages, 134139

traits, 174176

reverse sorting functions, 83, 8990

reversing arrays, 92

REVOKE command, 230, 230231

rewind() function, 7071

RFCs (Requests for Comments), 404

rmdir() function, 394

row subqueries, 264

rows, 211

inserting into SQL database, 248250

non-matching rows, finding, 256257

rsort() function, 83

rules

for identifiers, 239

of variable scope, 27

running PHP on command line, 526527

runtime environment, temporarily modifying, 524525

runtime errors, 544549

causes of, 545549

calls to nonexistent functions, 545546

connections to network services, 548549

failure to check input data, 549

interaction with MySQL, 547548

reading or writing files, 546547

S

SaaS version control systems, 537

scalar values, 26

scalar variables, creating from arrays, 99100

scandir.php, 393

schemas, 212

scope, 27, 148150

<script> tag, 494495

scripts

add_bms.php, 588589

adding locks to, 7173

authmain.php, 483489

basic_auth.php, 372373

bookmark_fns.php, 567568

browsedir2.php, 392

browsedir.php, 390

chat.php, 504507

delete_bms.php, 592593

directory_submit.php, 409412

dump_variables.php, 551553

executing on command line, 526527

filedetails.php, 395396

forgot_passwd.php, 583584

ftp_mirror.php, 413416

functions, calling, 19

handle.php, 558

list_functions.php, 522523

login.php, 566567

logout.php, 490491

lookup.php, 405

make_button.php, 458460

member.php, 576577

members_only.php, 489

modification date, obtaining, 523524

owner, identifying, 523

processfeedback_v2.php, 108109

processfeedback.php, 101104

processorder.php

creating, 14

dynamic content, adding, 1819

with exception handling, 205208

progex.php, 400401

recommend.php, 595597

register_form.php, 569570

register_new.php, 570572

results.php, 273275

scandir.php, 393

secret.php, 369

show poll.php, 468474

simplegraph.php, 451452

stopping, 50

terminating, 520522

upload.php, 382387

vieworders.php, 6566

search form (Book-0-Rama bookstore application), 272273

secret.php, 367369

security

application security threats

access to sensitive data, 331333

actors, 339340

compromised server, 338

denial of service, 335337

loss of data, 334335

malicious code injection, 337

modification of data, 334

repudiation, 338339

attackers, 339

authentication

access control, 366369

basic authentication, 372377

custom authentication, creating, 377

passwords, 369371

PHPbookmark project, 569587

in session control, 483491

visitors, identifying, 365366

character sets, 439440

code, securing, 343

bugs, 352353

escaping output, 348350

filtering user input, 343348

organizing code, 350351

crackers, 339

database servers, securing, 357359

disaster planning, 362364

file systems, 352

MySQL, 299301

passwords, 300

user privileges, 300301

web issues, 301

networks, securing, 360361

denial of service attacks, 361

DMZ, 360361

firewalls, 360

operating system, securing, 361362

permissions, 59

strategies for handling, 341343

balancing security and usability, 342

monitoring, 342343

starting with the right mindset, 342

twofold approach to, 343

web pages, protecting, 371

web servers, securing, 354357

browsing php.ini file, 355356

shared hosting of web applications, 356357

updating software, 354355

SELECT command (SQL), 250251

evaluating, 304309

LIMIT clause, 261262

ORDER BY clause, 259

WHERE clause, 252253

comparison operators, 252253

selecting

HTML elements with selectors, 496497

MySQL database, 232

SQL databases from the web, 278

table types, 316

selectors (jQuery), 495498

acting on, 498

HTML elements, creating, 497498

pseudo-selectors, 497

syntax, 496497

sending email, 404

serialization, 521

serialize() function, 521

session control, 475

authentication, 483491

authmain.php, 483489

logout.php, 490491

members_only.php, 489

configuring, 482483

cookies, 476, 477

setting from PHP, 476477

session ID, storing, 477478

sessions

creating, 480482

destroying, 479

registering variables, 478479

starting, 478

session ID, 476

storing, 477478

session variables, 476, 479

unsetting, 479

session_start() function, 478

set_error_handler() function, 557558

_set() function, 166168

setcookie() function, 476

settype() function, 39

SGML (Standard Generalized Markup Language), 16

shared hosting of web applications, security issues, 356357

short style PHP tags, 16

SHOW command (MySQL), 301304

syntax, 303304

show poll.php, 468474

show tables command, 237

show_source() function, 525

shuffle() function, 9091

simple tables, 218

simplegraph.php, 451452

single-byte languages, 438

single-line comments, 18

size of files, determining, 70

sizeof() function, 9899

slaves, setting up for replication, 313

Smart Form Mail application

creating, 101104

regular expressions, 127128

SMTP (Simple Mail Transfer Protocol), 404

software, updating, 354355

Software Engineering: A Practitioner’s Approach, 542

software engineering, applying to web development, 530

solution components for PHPbookmark project, 561565

sort() function, 76, 8586

sorting arrays, 8587

with asort() function, 8687

with ksort() function, 8687

multidimensional arrays, 8790

reverse sorting, 83

with sort() function, 8586

source code, highlighting, 525526

special characters

meta characters, 124125

pattern matching, 123124

special privileges (MySQL), 230

splitting strings

explode() function, 112113

with regular expressions, 129130

with strtok() function, 113114

with substr() function, 114

sprintf() function, 109

SQL (Structured Query Language), 247248. See also MySQL

aggregating data, 259261

INSERT command, 248249

inserting data, 248250

joins

cross joins, 258

equi-joins, 258

full joins, 254255

inner joins, 258

joining more than two tables, 255256

left joins, 256257

querying from the Web, 275281

disconnecting from database, 281

filtering input data, 276

prepared statements, 279280

retrieving the results, 280281

selecting the database, 278

setting up connection, 277278

retrieving data, 250259

from multiple tables, 251253

SELECT command, 250251

with specific criteria, 251253

subqueries, 262263

correlated subqueries, 264

operators, 263

row subqueries, 264

as temporary table, 264

SSL (Secure Sockets Layer), troubleshooting, 610612

stand-alone functions, _autoload(), 189

starting sessions, 478

statements, 16. See also commands

echo, 22

else, 4243

elseif, 4344

if, 4142

LOAD DATA INFILE, 315

prepared statements, 279280

require(), 132134

applying templates to web pages, 134139

semicolons, 16

switch, 4445

static keyword, 185

status of variables, testing, 4041

stopping scripts, 50, 520522

storage engines, 316317

ARCHIVE, 316

CSV, 316

InnoDB, 316

foreign keys, 319

transactions, 318319

MEMORY, 316

MERGE, 316

MyISAM, 316

stored procedures, 320327

control structures, 323327

declare handlers, 325

cursors, 323, 325

example of, 320323

local variables, 323

storing

dates and times, Unix timestamps, 426427

orders, 54

passwords, 300, 369

in RDBMSs, 74

records, 62

session ID, 477478

str_replace() function, 107, 118119

strategies for handling security, 341343

balancing with usability, 342

monitoring, 342343

starting with the right mindset, 342

strcasecmp() function, 115

strchr() function, 117

strcmp() function, 115

strftime() function, 429431

string operators, 29

string type columns, 244246

strings. See also regular expressions

changing case of, 111112

checking length of, 115116

comparing, 115

concatenating, 22

creating from classes, 194

evaluating, 519520

filtering for output, 105107, 347348

to browser, 105106

to email, 106107

finding within strings, 116117

formatting

conversion specification, 109

for printing, 109111

heredoc syntax, 23

interpolation, 22

joining, 113

multibyte string functions, 440

ordering, 115

regular expressions, anchoring to beginning or end of, 123

splitting

explode() function, 112113

with regular expressions, 129130

with strtok() function, 113114

with substr() function, 114

substrings

find-and-replace operations, 118119

finding position of, 117118

replacing with string functions, 116

trimming, 104

stristr() function, 117

strlen() function, 115116

strnatcmp() function, 115

strpos() function, 117118

strstr() function, 116117

strtok() function, 113114

strtolower() function, 112

strtoupper() function, 112

structure

of classes, 162163

of functions, 144145

strval() function, 41

subclasses, 161162

inheritance, 168169

submit event, 504

subnamespaces, 197

subqueries, 262263

correlated subqueries, 264

operators, 263

row subqueries, 264

as temporary table, 264

substr() function, 114

substr_replace() function, 118119

substrings

find-and-replace operations, 118119

finding position of, 117118

finding with regular expressions, 128129

replacing

with regular expressions, 129

with string functions, 116

subtraction operator, 28

Subversion, 537

success key, 507

superclasses, 161162

superglobal arrays, 20, 27

support for images in PHP, setting up, 449450

switch statement, 4445

syntax

heredoc, 23

jQuery selectors, 496497

semicolons, 16

SHOW command, 303304

syntax errors, 543544

system() function, 399

T

table types

ARCHIVE, 316

CSV, 316

InnoDB, 316

foreign keys, 319

transactions, 318319

MEMORY, 316

MERGE, 316

MyISAM, 316

selecting, 316

tables, 210, 218

aliases, 257258

altering after creation, 265268

columns, 235237

CHAR type, 235

VARCHAR type, 235236

creating, 232234

displaying, 302

dropping, 268

grant tables, 292293

columns_priv table, 296298

connection verification, 298

db table, 295296

procs_priv table, 296298

request verification, 298

tables_priv table, 296298

user table, 293295

joining

full joins, 254255

left joins, 256257

linking tables, 218

optimizing, 310

records

deleting, 268

updating, 265

relationships, 213

retrieving data

criteria, specifying, 251253

from multiple tables, 251253

rows, inserting into SQL database, 248250

simple tables, 218

subqueries as temporary table, 264

triggers, 327329

viewing, 237238

tables_priv table, 296298

tags

JavaScript, <script> 494495

PHP, 16

short style, 16

XML style, 16

templates, applying to web pages, 134139

temporarily modifying runtime environment, 524525

terminating scripts, 520522

ternary operator, 34

testing

code, 541542

PHP support, 610

variable status, 4041

text

applying to buttons, 461464

bounding box, 462463

descenders, 463

positioning on buttons, 464

regular expressions

anchoring to beginning or end of string, 123

assertions, 126127

backreferences, 126

branching, 123

character class, 121122

character sets, 120121

counted subexpressions, 123

delimiters, 120

escape sequences, 125126

meta characters, 124125

repetition, 122

in Smart Form Mail application, 127128

special characters, matching, 123124

strings, splitting, 129130

substrings, finding, 128129

writing on buttons, 464465

threats to web application security

access to sensitive data, 331333

actors, 339340

compromised server, 338

denial of service, 335337

malicious code injection, 337

modification of data, 334

repudiation, 338339

three-dimensional arrays, 8485

throw keyword, 200

time, microseconds, 435

timestamps, formatting, 429431

timezones, 423424

top-down approach to security, 343

totals, calculating on order forms, 3637

tracking file upload progress, 387388

traits, 174176

transactions, 317319

using InnoDB, 318319

translation files, 445447

trigger_error() function, 556

triggering your own errors, 556

triggers, 327329

trim() function, 104

trimming strings, 104

troubleshooting. See also error handling; exception handling

with EXPLAIN command, 308309

file upload, 389

opening files, 5861

SSL, 610612

TrueType fonts, 457

try blocks, 199

two-dimensional arrays, 8284

twofold approach to security, 343

two-table joins, 254255

type casting, 25

type codes for conversion specification, 110111

type hinting, 185186

type operator, 35

type strength, 25

U

uasort() function, 89

ucfirst() function, 112

ucwords() function, 112

uksort() function, 89

umask() function, 394

unary operator, 2829

undefined functions, calling, 142143

UNIX

Apache, installing, 600602

MySQL, installing, 602605

PHP, installing, 605609

Unix Epoch, 426

Unix timestamps, 426427

converting date and time to, 426

UNIX_TIMESTAMP() function, 432433

unlink() function, 70

unserialize() function, 521

unsetting session variables, 479

update anomalies, 215

UPDATE command (SQL), 265

updating

privileges, 299

records, 265

software, 354355

uploading files, 379389, 420

HTML form, 381382

php.ini settings, 380381

tracking upload progress, 387388

troubleshooting, 389

writing the file handling script, 382387

upload.php, 382387

urlencode() function, 407

usability, balancing with security, 342

use command, 232

user interface for chat application, building, 504507

user personalization, 561

user table, 293295

user-defined exceptions, 202204

user-defined functions, 144

parameters, 147

user-defined sorts, 8889

users

authentication, identifying visitors, 365366

MySQL, 225232

creating, 224, 225227

principle of least privilege, 225

privileges, 227230, 300301

privileges (MySQL), 291299

web access, 231232

usort() function, 8889

V

val() method, 498

validating dates with checkdate() function, 428429

values, 211

atomic column values, 216217

basic values, filtering, 346347

null values, 217218

VARCHAR type columns, 235236

variable functions, 146

variable handling functions, 3940

variable variables, 2526

variables, 23

accessing, 2022

arrays, 7576

accessing contents, 7778

converting to scalar variables, 99100

initializing, 79

loading from files, 9296

multidimensional arrays, 75

navigating, 9697

numerically indexed arrays, 7677

reordering, 9091

reversing, 92

sorting, 8587

three-dimensional arrays, 8485

two-dimensional arrays, 8284

assigning values to, 24

assignment operators, 20

and constants, 26

data types, 2425

scalar values, 26

type casting, 25

type strength, 25

debugging, 551553

environment variables, 401402

handles, 161

identifiers, 2324

interpolation, 22

local variables, 323

scope, 27, 148150

serializing, 521

session variables, 476, 479

registering, 478479

unsetting, 479

status, testing, 4041

version control, 536537

viewing tables, 237238

vieworders.php script, 6566

visibility, controlling, 169170

visitors, identifying, 365366

vprintf() function, 111

vsprintf() function, 111

W

web access, configuring for MySQL users, 231232

web application development

applying to software engineering, 530

chat application

chat server, building, 504507

user interface, building, 510517

internationalized software, 437438

jQuery, 494495

large projects

breaking up code, 535536

choosing a development environment, 537538

coding standards, 532

commenting your code, 534

defining naming conventions, 532534

directory structure, 536

documenting, 538

function libraries, 536

indenting code, 534535

optimizing code, 540541

planning, 530531

prototyping, 538539

separating logic from content, 539540

testing code, 541542

version control, 536537

writing maintainable code, 532

localization, 437438

character sets, 438440

locales, 438

operating system, securing, 361362

reusing code, 531532

security

code, securing, 343352

database servers, securing, 357359

disaster planning, 362364

executing commands, 353354

file system considerations, 352

network security, 360361

strategies for handling, 341343

web servers, 354357

threats

access to sensitive data, 331333

compromised server, 338

denial of service, 335337

loss of data, 334335

malicious code injection, 337

modification of data, 334

repudiation, 338339

web database architecture, 218220, 272

web pages

internationalization

language selector page, 442444

locale-specific headers, 441442

localizing, 440445

protecting, 371

templates, applying with require() statement, 134139

web servers, 218219

Apache HTTP Server

.htaccess files, 374377

configuring, 356

Nginx, 614

security, 354357

browsing php.ini file, 355356

shared hosting of web applications, 356357

updating software, 354355

websites

Bill Gates Wealth Clock, 407

consuming date from other sites, 404408

cookies, 476, 477

session ID, storing, 477478

setting from PHP, 476477

session control, 475

visitors, identifying, 365366

WHERE clause (SELECT command), 252253

comparison operators, 252253

while loops, 4748

whitespace, 17

Windows operating system, installation packages, 612613

writing

code for classes, 177184

accessor functions, 178

attributes, 177

metatags, 177

operations, 181

file upload script, 382387

to files, 55, 61

as cause for runtime errors, 546547

text on buttons, 464465

X

XML, AJAX, 493494

XML style PHP tags, 16

XOR operator, 3233

Y-Z

yield keyword, 192193

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset