C o n t e n t s xxi C o n t e n t s xxi Plug-in 89: Words from Root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302 About the Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 Variables, Arrays, and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 How to Use It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 The Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 Plug-in 90: Predict Word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 About the Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 Variables, Arrays, and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 How to Use It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 The Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 12 Diverse Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 Plug-in 91: Get Country by IP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 About the Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 Variables, Arrays, and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 How it Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 How to Use It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 The Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312 Plug-in 92: Bypass Captcha . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312 About the Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313 Variables, Arrays, and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313 How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313 How to Use It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313 The Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 Plug-in 93: Get Book from ISBN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 About the Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 Variables, Arrays, and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 How to Use It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 The Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 Plug-in 94: Get Amazon Sales Rank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 About the Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 Variables, Arrays, and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317 How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317 How to Use It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317 The Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318 Plug-in 95: Pattern Match Word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318 About the Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 Variables, Arrays, and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 How to Use It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320 The Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320 Plug-in 96: Suggest Spelling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320 About the Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320 Variables, Arrays, and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 How to Use It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322 The Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 Plug-in 97: Google Translate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324 About the Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324 Variables, Arrays, and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 How to Use It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 The Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326 Plug-in 98: Corner Gif . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327 About the Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327 Variables, Arrays, and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328 How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328 How to Use It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328 The Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329 Plug-in 99: Rounded Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330 About the Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 Variables, Arrays, and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 How to Use It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 The Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332 Plug-in 100: Display Bing Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332 About the Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 Variables, Arrays, and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 How to Use It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 The Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335 xxii P l u g - i n P H P : 1 0 0 P o w e r S o l u t i o n s Acknowledgments T hanks to everyone who worked with me on this book, particularly Wendy, Todd, Joya, Mike, Vipra, and Melinda, without whom this book simply would not be the same. In fact, the whole team at McGraw-Hill is a pleasure to work with and I thank you all for your, kindness, intelligent insights, and support. xxiii This page intentionally left blank Introduction P HP is an open-source (and therefore free) scripting language for creating dynamic web pages. Since its creation in 1995, its popularity has grown to more than double that of the previously most used scripting language, Perl. In fact, PHP is now in the top five most popular and most used languages according to a majority of surveys, which is hardly surprising because it is provided with most web hosting accounts, is easy to integrate into web pages, is extremely fast (given that it is interpreted), and it has built-in links to MySQL, the world’s most popular open-source database program. Because it was written by and for programmers, PHP comes with an extensive library of features and functions that may baffle a beginner. But it is possible to use just a small core subset of these to create most of the dynamic content a webmaster could need, which is precisely what this book demonstrates. Plug-in PHP is aimed squarely at web site owners who have learned basic HTML and PHP and are interested in doing more with their sites. For example, you may wish to create member areas protected by usernames and passwords, or want to write a simple Guestbook and so on. Using Plug-in PHP, you will learn how to do all these things and much more using very simple ready-made PHP. It is never assumed that you already know something, so you are taken through each subject step by step with full explanations, making sure you never have to go elsewhere to find the information you need. This book also purposefully ignores mor e advanced topics such as object-oriented programming. Instead, the code samples look very much like a cross between simple C and Basic. Elegant, tight structures that more advanced programmers might appreciate are set aside in preference for more understandable code, where the flow from any point to any other is as obvious as possible. All of the plug-ins and examples are written in a complete and ready-to-use form that you can type into your own web pages. Even if you have almost no knowledge of programming, you can still make full use of the book, which can be dipped into as required since each chapter is mostly self-contained. This means that wherever you have a pr oblem on your web site you can simply refer to the relevant chapter, which should be all you need to solve it. To help you get up and running with these plug-ins, the first chapter walks you through how to set up your own web development server on a PC, Mac, or Linux computer, while the second shows how best to integrate the plug-ins into your own programs. xxv . Guestbook and so on. Using Plug- in PHP, you will learn how to do all these things and much more using very simple ready-made PHP. It is never assumed that you already know something, so you are taken. precisely what this book demonstrates. Plug- in PHP is aimed squarely at web site owners who have learned basic HTML and PHP and are interested in doing more with their sites. For example, you. these plug- ins, the first chapter walks you through how to set up your own web development server on a PC, Mac, or Linux computer, while the second shows how best to integrate the plug- ins into