Codin' for the Web
Table of Contents
- Introduction • xiv
- Chapter 1 : XHTML: Coding Principles • 2
- How PHP Works • 4
- Variables • 6
- Creating Variables • 7
- Naming Variables • 7
- Using print and echo • 8
- Numeric Variables • 11
- Operators • 12
- Assignment Operator • 12
- Math Operators • 12
- Comparison Operators • 13
- Increment and Decrement Operators • 13
- Concatenating (Joining) Operator • 15
- Operator Precedence and Parentheses • 15
- Strings • 16
- Arrays • 20
- Indexed Arrays • 20
- Associative Arrays • 22
- Functions • 23
- Calling a Function • 24
- Writing a Function • 24
- Code Structures • 26
- The If-then-else Structure • 27
- PHP’s Simple if-then-else Structure • 29
- The else-if Structure • 31
- Converting Part of a Script to a Function • 32
- Loops • 34
- The while Loop • 34
- The for Loop: The Iterator • 34
- The foreach Loop • 37
- Objects • 40
- Summary • 42
- Chapter 2 : Processing Forms • 44
- About User-Supplied Data and the Need for Validation • 46
- Is There Any Data at All? • 48
- Check for a Specific Character or Word • 48
- Check for Patterns in the Data • 48
- Creating the Form • 50
- Creating the XHTML for a Form • 50
- Creating a Self-Requesting Page • 52
- Using the $_POST Super-Global Array • 55
- Sending E-mail to Yourself with PHP • 57
- Creating Sticky Stay-Filled Forms • 59
- Combating Magic Quotes • 61
- Validating Your Forms • 63
- Checking for Empty Fields • 64
- Validating Multiple Fields • 65
- Building an Error Message Array • 65
- Creating an XHTML List of the Error Messages • 66
- Checking for Specific Characters • 71
- Validating with Regular Expressions • 72
- Using Some Simple Regular Expressions • 73
- Validating an E-mail Address Pattern • 75
- Using an Include to Add the Regular Expressions • 75
- Working with Flat Files • 80
- Choosing the Read/Write Mode • 81
- Storing Flat Files above the Root Folder • 82
- Creating a Flat File • 83
- Writing to a File • 83
- Creating a File: Code Example • 84
- Importing a Tab-Delimited File into Excel • 86
- Creating a Write-to-File Function • 88
- Reading a Flat File with PHP • 90
- Reading a Flat File Line by Line • 90
- Extracting Each Element of the Record • 91
- Displacing the File in a Table • 92
- Summary • 93
- About User-Supplied Data and the Need for Validation • 46
- Chapter 3 : Databases • 94
- Data Types and Lengths • 97
- Creating the Database and Tables • 98
- Creating a Database • 99
- Creating a Table • 100
- Connecting with Your Database • 103
- Opening a connection • 103
- Selecting a Database • 105
- Using INSERT to Add Data to a Table • 105
- Closing the Connection • 106
- INSERT: An Example • 106
- Using SELECT to Read Data from the Database • 107
- Specifying Fields to Retrieve • 111
- Matching with WHERE in SELECT Statements • 111
- Using UPDATE to Modify Values in a Record • 112
- Using DELETE to Remove a Record from a Table • 113
- Summary • 114
- Chapter 4 : Content Management • 116
- Public Pages and Administration Pages: Overview • 118
- Creating the Database Tables • 121
- Creating the Listings Table • 122
- Creating the Categories Table • 123
- Creating the Edit Links Form • 124
- Setting up the Database Connection • 127
- Displaying the Categories in the Topic Category Drop-Down Menu • 128
- Adding Content to the Database Using the Edit Links Form • 130
- Creating the Links Admin Page • 132
- Displaying the Listings Records from the Database • 132
- Writing the Listings Records in a Table • 134
- Displaying the Links Table Organized by Category • 137
- The Plan • 137
- Writing a SQL JOIN Query • 137
- Adding the Category Headings to the Table • 139
- Adding Modify and Delete Links to Each Record • 141
- Coding the Modify and Delete Links • 142
- Coding the Delete Functionality • 143
- Modifying a Record: Going Back to the Edit Links Form Page • 146
- Four Possible Edit Links Form Activities • 146
- Coding the Edit Links Form to Modify Records • 148
- Retrieving One Record Using a SQL JOIN Query • 148
- Displaying the Retrieved Data in the Edit Links Form Fields • 150
- Making the Menu Sticky • 151
- Updating a Record • 153
- Sharing Variables between Queries • 154
- Writing the UPDATE Query • 155
- Adding Finishing Touches to the Edit Links Form Page • 157
- Redirecting when a Records Is Successfully Added • 157
- Adding a Link to the Links Admin Page • 158
- Adding Finishing Touches to the Links Admin Page • 158
- Adding CSS Styles to the Links Admin Page • 159
- Truncating the Displayed URL Strings • 160
- Adding the Success Messages • 163
- Creating the Public Listing Page • 165
- Summary • 169
- Chapter 5 : Cookies and Authentication • 170
- Cookies and the Session State • 173
- Maintaining the Session State • 174
- Using Cookies • 175
- Creating a Cookie • 176
- Updating and Deleting Cookies • 176
- Using Single-Session Cookies • 177
- Setting a Cookie • 178
- Using the time Function • 179
- He’s Baaaack! • 179
- Creating Data-Rich Cookies • 180
- Using explode and implode to Convert between Arrays and Strings • 180
- Authentication Basics • 182
- Creating an Authentication System • 185
- Sign Up, Sign In: Registration and Credentials • 185
- Creating the Authentication System Architecture • 185
- Creating the Database Table • 190
- Adding Database Functions • 190
- Creating the Authentication System Pages • 193
- Creating the Sign-Up Page • 193
- Creating the Members Only Page • 198
- Creating the Not-Signed-In Page • 200
- Creating the Lost Password Page • 202
- Creating the Sign-In Page • 205
- Summary • 208
- Cookies and the Session State • 173
- Chapter 6 : Building a Web Site with PHP • 210
- Using include Files to Build Pages • 212
- Creating the XHTML include Files • 215
- Creating the Navigation include Files • 216
- Creating the Reference Links Folder • 218
- Creating a Config File • 221
- Setting Up the Database include Files • 223
- Activating the Navigation Links • 226
- Adding the Administration Pages • 227
- Transferring the Admin Page Code to the Page Template • 227
- Moving the CSS to the Style Sheet • 228
- Building the Links Form Page • 231
- Beware the Headers Already Sent Error Message • 235
- Testing the Form • 236
- Adding the Admin Link to the Navigation • 237
- Implementing the Authentication System • 238
- Setting Up the Admin include Files • 238
- Adding the Member’s Page • 243
- Adding the Sign-in Page • 245
- Securing the Admin Area • 248
- Adding the No-Credentials Page • 249
- Adding the Lost Password Page • 251
- Adding a Downloads Page • 253
- Improving the Navigation Bar • 255
- Making a Background Image Clickable • 256
- Creating Dynamic Navigation • 257
- Setting Up the Site Navigation Structure • 258
- Displaying the Contents of the Top-Level Folder • 259
- Distinguishing between Folders and Files • 261
- Creating an Absolute Path to the Top-Level Folder • 262
- Filtering Out the Unix Folders • 262
- Changing the Folder Names to Display Names • 266
- Generating the Links • 269
- Making the Page Titles Dynamic • 271
- Adding Dynamic Page Title Code to the Page Top include File • 273
- Reviewing Our Dynamic Site • 274
- Index • 277
- Using include Files to Build Pages • 212
- Chapter A : Unleashing the Geek Within • A-1
- Form versus Function • A-3
- Use Cases • A-4
- Dynamic Web Sites • A-6
- Three-Tier Architecture • A-8
- Interface • A-8
- Middleware • A-9
- Database • A-10
- Anatomy of the Interface • A-10
- Interface Components • A-10
- Structure of the Interface: Hierarchical Page Structure • A-12
- Interface Summary • A-14
- Middleware • A-14
- The Concept of Templates • A-16
- The Concept of include Files • A-18
- Middleware Summary • A-20
- Database • A-20
- Structure of a Database • A-21
- Structured Query Language: SQL • A-24
- Database Summary • A-26
- Summary • A-26
- Chapter B : Coding the Interface • B-1
- Writing Code • B-3
- Using XHTML and CSS • B-4
- Writing Good XHTML • B-5
- Writing XHTML Tags • B-6
- Specifying Tag Attributes • B-7
- Rules for XHTML Markup • B-8
- Coding the Interface • B-10
- About Block Elements • B-12
- About Inline Elements • B-12
- Code Element Boxes • B-13
- Using div Tags to Give Content Structure • B-15
- Creating Navigation Elements • B-19
- Creating a Multicolumn Page Layout • B-21
- Setting the Width of Elements • B-21
- Adding a Header • B-26
- Completing the Layout • B-27
- Moving the Styles to a Style Sheet • B-32
- Summary • B-33