Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Instead of starting at "Hello World," Wicked Cool PHP assumes that you're familiar with the language and jumps right into the good stuff. After you learn the FAQs of life-the most commonly wished for PHP scripts-you'll work your way through smart configuration options and the art of forms, all the way through to complex database-backed scripts.Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text. The 76 easily implemented scripts will also teach you how to:Send and receive email notifications Track your visitors' behavior with cookies and sessions Override PHP's default settings Manipulate dates, images, and text on the fly Harness SOAP and other web services Create an online poll, ecard delivery system, and blogBut it's not all fun and games: Security is a big concern when programming any web application. So you'll learn how to encrypt your confidential data, safeguard your passwords, and prevent common cross-site-scripting attacks. And you'll learn how to customize all of the scripts to fit your own needs.Dynamic Web content doesn't have to be difficult. Learn the secrets of the craft from two experienced PHP developers with Wicked Cool PHP.

Author(s): William Steinmetz, Brian Ward
Edition: 1
Publisher: No Starch Press
Year: 2008

Language: English
Commentary: PDF from HTML
Pages: 183

2. Table of Contents......Page 2
3. WICKED COOL PHP.......Page 4
4. INTRODUCTION......Page 6
1.1. #1: Including Another File as a Part of Your Script......Page 7
1.1.1. What Can Go Wrong?......Page 8
1.1. #1: Including Another File as a Part of Your Script......Page 10
1.1.1. What Can Go Wrong?......Page 11
1.2. #2: Highlighting Alternate Row Colors in a Table......Page 12
1.2.1. Hacking the Script......Page 13
1.3. #3: Creating Previous/Next Links......Page 14
1.3.1. Using the Script......Page 16
1.4. #4: Printing the Contents of an Array......Page 17
1.5. #5: Turning an Array into a Nonarray Variable That Can Be Restored Later......Page 18
1.6. #6: Sorting Multidimensional Arrays......Page 19
1.7.1. Installing Smarty......Page 20
1.7.2. A Brief Smarty Tutorial......Page 21
1.7.4. Hacking the Script......Page 22
2.1.1. Locating Your php.ini File......Page 23
2.1. Configuration Settings and the php.ini File......Page 24
2.3. #9: Reading an Individual Setting......Page 25
2.4. #10: Error Reporting......Page 26
2.5. #11: Suppressing All Error Messages......Page 27
2.6.1. What Can Go Wrong?......Page 28
2.9.1. What Can Go Wrong?......Page 29
2.12. #18: Adding Extensions to PHP......Page 30
2.12.1. Adding PHP Extensions......Page 31
2.12.2. Installing Extensions with a Web-Based Control Panel......Page 32
2.12.3. What Can Go Wrong?......Page 34
7. Chapter 3. PHP SECURITY......Page 35
3.1. Recommended Security Configuration Options......Page 36
3.2. #19: SQL Injection Attacks......Page 39
3.3. #20: Preventing Basic XSS Attacks......Page 41
3.4. #21: Using SafeHTML......Page 42
3.5. #22: Protecting Data with a One-Way Hash......Page 43
3.6. #23: Encrypting Data with Mcrypt......Page 44
3.7.1. Using the Script......Page 46
4.1. Security Measures: Forms Are Not Trustworthy......Page 47
4.2. Verification Strategies......Page 48
4.4. #25: Fetching Form Variables Consistently and Safely......Page 49
4.6. #27: Importing Form Variables into an Array......Page 50
4.7. #28: Making Sure a Response Is One of a Set of Given Values......Page 52
4.8. #29: Using Multiple Submit Buttons......Page 53
4.9. #30: Validating a Credit Card......Page 54
4.9.1. Using the Script......Page 55
4.10. #31: Double-Checking a Credit Card's Expiration Date......Page 56
4.11. #32: Checking Valid Email Addresses......Page 57
5.1. #34: Extracting Part of a String......Page 58
5.1.1. Hacking the Script......Page 60
5.1. #34: Extracting Part of a String......Page 61
5.1.1. Hacking the Script......Page 62
5.2.1. What Can Go Wrong?......Page 63
5.3.1. What Can Go Wrong?......Page 64
5.5. #38: Finding and Fixing Misspelled Words with pspell......Page 65
5.5.1. Working with the Default Dictionary......Page 66
5.6. #39: Regular Expressions......Page 68
5.6.2. Special Character Sequences......Page 69
5.6.6. Putting It All Together......Page 70
5.6.7. Matching and Extracting with Regular Expressions......Page 71
5.7. #40: Rearranging a Table......Page 72
5.8. #41: Creating a Screen Scraper......Page 73
5.8.1. Hacking the Script......Page 74
5.9. #42: Converting Plaintext into HTML-Ready Markup......Page 75
10. Chapter 6. WORKING WITH DATES......Page 77
6.1. How Unix Time Works......Page 78
6.3.1. Creating Timestamps from a String......Page 80
6.3.2. Creating Timestamps from Date Values......Page 82
6.4. #47: Formatting Dates and Times......Page 83
6.5. #48: Calculating the Day of the Week from a Given Date......Page 85
6.6.1. Using the Script......Page 86
11. Chapter 7. WORKING WITH FILES......Page 87
7.1. File Permissions......Page 88
7.1. File Permissions......Page 89
7.1.3. What Can Go Wrong?......Page 90
7.2. #50: Placing a File's Contents into a Variable......Page 91
7.2.2. What Can Go Wrong?......Page 92
7.5. #53: Deleting Files......Page 93
7.6. #54: Uploading Images to a Directory......Page 94
7.7. #55: Reading a Comma-Separated File......Page 97
12. Chapter 8. USER AND SESSION TRACKING......Page 98
8.1.2. Sessions......Page 99
8.1. Using Cookies and Sessions to Track User Data......Page 100
8.1.2. Sessions......Page 101
8.2.1. What Can Go Wrong?......Page 102
8.3. #57: Using Sessions to Temporarily Store Data......Page 103
8.3.1. What Can Go Wrong?......Page 104
8.5. #59: Redirecting Users to Different Pages......Page 105
8.6. #60: Forcing a User to Use SSL-Encrypted Pages......Page 106
8.7. #61: Extracting Client Information......Page 107
8.8. #62: Session Timeouts......Page 110
8.9. #63: A Simple Login System......Page 111
9.1. #64: Using PHPMailer to Send Mail......Page 112
9.1.1. Installing PHPMailer......Page 113
9.1.3. Adding Attachments......Page 114
9.1.4. What Can Go Wrong?......Page 115
9.1.1. Installing PHPMailer......Page 116
9.1.2. Using the Script......Page 117
9.1.3. Adding Attachments......Page 118
9.2. #65: Using Email to Verify User Accounts......Page 119
10.1. #66: Creating a CAPTCHA (Security) Image......Page 122
10.2. #67: Creating Thumbnail Images......Page 133
15. Chapter 11. USING cURL TO INTERACT WITH WEB SERVICES......Page 135
11.1. #68: Connecting to Other Websites......Page 136
11.3. #70: Transforming XML into a Usable Form......Page 140
11.4. #71: Using Mapping Web Services......Page 142
11.5. #72: Using PHP and SOAP to Request Data from Amazon.com......Page 144
11.6. #73: Building a Web Service......Page 147
16. Chapter 12. INTERMEDIATE PROJECTS......Page 148
12.1. #74: A User Poll......Page 149
12.1.1. Creating a Ballot Form......Page 150
12.1.2. Processing the Ballot......Page 151
12.1.3. Getting Poll Results......Page 152
12.1.4. Hacking the Script......Page 154
12.1. #74: A User Poll......Page 155
12.1.1. Creating a Ballot Form......Page 156
12.1.2. Processing the Ballot......Page 158
12.1.3. Getting Poll Results......Page 159
12.2. #75: Electronic Greeting Cards......Page 161
12.2.1. Choosing a Card......Page 162
12.2.2. Sending the Card......Page 163
12.2.3. Viewing the Card......Page 167
12.3. #76: A Blogging System......Page 169
12.3.1. Creating Blog Entries......Page 170
12.3.2. Displaying an Entry......Page 172
12.3.3. Adding Comments......Page 175
12.3.4. Creating a Blog Index......Page 176
17. Appendix A. APPENDIX......Page 178
19. Index......Page 179