Chapter 2: Understanding and Avoiding Security Risks
Identifying the Sources of Risk
Minimizing User-Input Risks
Not Revealing Sensitive Information
Summary
Chapter 3: PHP Best Practices
Best Practices for Naming Variables and Functions
Best Practices for Function/Method
Best Practices for Database
Best Practices for User Interface
Best Practices for Documentation
Best Practices for Web Security
Best Practices for Source Configuration Management
Summary
Part II
Chapter 4: Architecture of an Intranet Application
Understanding Intranet Requirements
Building an Intranet Application Framework
Creating a Database Abstraction Class
Creating an Error Handler Class
Creating a Built-In Debugger Class
Creating an Abstract Application Class
Creating a Sample Application
Summary
Chapter 5: Central Authentication System
How the System Works
Creating an Authentication Class
Creating the Central Login Application
Creating the Central Logout Application
Creating the Central Authentication Database
Testing Central Login and Logout
Making Persistent Logins in Web Server Farms
Summary
Chapter 6: Central User Management System
Identifying the Functionality Requirements
Creating a User Class
User Interface Templates
Creating a User Administration Application
Creating a User Password Application
Creating a Forgotten-Password Recovery Application
Summary
Chapter 7: Intranet System
Identifying Functionality Requirements
Designing the Database
Designing and Implementing the Intranet Classes
Setting Up Application Configuration Files
Setting Up the Application Templates
Intranet Home Application
Installing Intranet Applications from the CD- ROM
Testing the Intranet Home Application
Summary
Chapter 8: Intranet Simple Document Publisher
Identifying the Functionality Requirements
The Prerequisites
Designing the Database
The Intranet Document Application Classes
Setting up Application Configuration Files
Setting Up the Application Templates
The Document Publisher Application
Installing Intranet Document Application
Testing Intranet Document Application
Summary
Chapter 9: Intranet Contact Manager
Functionality Requirements
Understanding Prerequisites
The Database
The Intranet Contact Manager Application Classes
The Application Configuration Files
The Application Templates
The Contact Category Manager Application
The Contact Manager Application
Installing Intranet Contract Manager
Testing Contract Manager
Summary
Chapter 10: Intranet Calendar Manager
Identifying Functionality Requirements
Understanding Prerequisites
Designing the Database
The Intranet Calendar Application Event Class
The Application Configuration Files
The Application Templates
The Calendar Manager Application
The Calendar Event Manager Application
Installing the Event Calendar on Your Intranet
Testing the Event Calendar
Summary
Chapter 11: Internet Resource Manager
Functionality Requirements
Understanding the Prerequisites
Designing the Database
Designing and Implementing the Internet Resource Manager Application Classes
Creating Application Configuration Files
Creating Application Templates
Creating a Category Manager Application
Creating a Resource Manager Application
Creating a Resource Tracking Application
Creating a Search Manager Application
Installing an IRM on Your Intranet
Testing IRM
Security Concerns
Summary
Chapter 12: Online Help System
Functionality Requirements
Understanding the Prerequisites
Designing and Implementing the Help Application Classes
Creating Application Configuration Files
Creating Application Templates
Creating the Help Indexing Application
Creating the Help Application
Installing Help Applications
Testing the Help System
Security Considerations
Summary
Part III
Chapter 13: Tell-a-Friend System
Functionality Requirements
Understanding Prerequisites
Designing the Database
Designing and Implementing the Tell- a- Friend Application Classes
Creating Application Configuration Files
Creating Application Templates
Creating the Tell-a-Friend Main Menu Manager Application
Creating a Tell-a-Friend Form Manager Application
Creating a Tell-a-Friend Message Manager Application
Creating a Tell-a-Friend Form Processor Application
Creating a Tell-a-Friend Subscriber Application
Creating a Tell-a-Friend Reporter Application
Installing a Tell-a-Friend System
Testing the Tell-a-Friend System
Security Considerations
Summary
Chapter 14: E-mail Survey System
Functionality Requirements
Architecture of the Survey System
Designing the Database
Designing and Implementing the Survey Classes
Designing and Implementing the Survey Applications
Developing Survey Execution Manager
Setting Up the Central Survey Configuration File
Setting Up the Interface Template Files
Testing the Survey System
Security Considerations
Summary
Chapter 15: E-campaign System
Features of an E-campaign System
Architecting an E-campaign System
Designing an E-campaign Database
Understanding Customer Database Requirements
Designing E-campaign Classes
Creating Common Configuration and Resource Files
Creating Interface Template Files
Creating an E-campaign User Interface Application
Creating a List Manager Application
Creating a URL Manager Application
Creating a Message Manager Application
Creating a Campaign Manager Application
Creating a Campaign Execution Application
Creating a URL Tracking and Redirection Application
Creating an Unsubscription Tracking Application
Creating a Campaign Reporting Application
Testing the E-Campaign System
Security Considerations
Summary
Part IV
Chapter 16: Command-Line PHP Utilities
Working with the Command-Line Interpreter
Building a Simple Reminder Tool
Building a Geo Location Finder Tool for IP
Building a Hard Disk Usage Monitoring Utility
Building a CPU Load Monitoring Utility
Summary
Chapter 17: Apache Virtual Host Maker
Understanding an Apache Virtual Host
Defining Configuration Tasks
Creating a Configuration Script
Developing makesite
Installing makesite on Your System
Testing makesite
Summary
Chapter 18: BIND Domain Manager
Features of makezone
Creating the Configuration File
Understanding makezone
Installing makezone
Testing makezone
Summary
Part V
Chapter 19: Web Forms Manager
Functionality Requirements
Understanding Prerequisites
Designing the Database
Designing and Implementing the Web Forms Manager Application Classes
Creating the Application Configuration Files
Creating Application Templates
Creating the Web Forms Submission Manager Application
Creating the Web Forms Reporter Application
Creating the CSV Data Exporter Application
Installing the Web Forms Manager
Testing the Web Forms Manager
Security Considerations
Summary
Chapter 20: Web Site Tools
Functionality Requirements
Understanding Prerequisites
Designing the Database
Designing and Implementing the Voting Tool Application Class
Creating the Application Configuration Files
Creating the Application Templates
Creating the Vote Application
Installing the Voting Tool
Testing the Voting Tool
Summary
Part VI
Chapter 21: Speeding Up PHP Applications
Benchmarking Your PHP Application
Buffering Your PHP Application Output
Compressing Your PHP Application Output
Caching Your PHP Applications
Summary
Chapter 22: Securing PHP Applications
Controlling Access to Your PHP Applications
Securely Uploading Files
Using Safe Database Access
Recommended php.ini Settings for a Production Environment
Limiting File System Access for PHP Scripts
Running PHP Applications in Safe Mode
Summary
Part VII
Appendix A: What's on the CD-ROM
System Requirements
What's on the CD
Troubleshooting
Appendix B: PHP Primer
Object-Oriented PHP
Appendix C: MySQL Primer
Using MySQL from the Command- Line
Using phpMyAdmin to Manage MySQL Database
Appendix D: Linux Primer
Installing and Configuring Apache 2.0
Installing and Configuring MySQL Server
Installing and Configuring PHP for Apache 2.0
Common File/Directory Commands
Index
Wiley Publishing, Inc. End-User License Agreement
Nội dung
◆ getReminders(): This method returns all reminders for the given contact ID. It works as follows: ■ First it sets the given contact ID using the setContactID() method. ■ A SQL statement, $stmt, is created to select all the reminder informa- tion for the given contact ID. ■ The SQL statement is executed using $this->dbi->query(), and the result is stored in $result. ■ If there are more than zero rows in the $result object, each row is fetched in the $row variable. ■ All reminders found in the result set are stored in an array. ■ The method returns the array if the result set is not empty; otherwise, it returns null. ◆ getMails(): This method returns all e-mails for the given contact num- ber. This is how it works: ■ It sets the given contact ID using the setContactID() method. ■ A SQL statement, $stmt, is created to select all the e-mails sent to the given contact. ■ The SQL statement is executed using $this->dbi->query(), and the result is stored in $result. ■ If there are more than zero rows in the $result object, each row is fetched in the $row variable. ■ All e-mails found in the result set are stored in an array. ■ The method returns the array if the result set is not empty; otherwise, it returns null. Here are the other methods in this class: Method Description addKeywords() Adds new keywords for the given contact. It explodes the $keyword string passed as a parameter and stores the different keywords in an array; for each keyword in the array, it adds a new entry in the CONTACT_KEYWORD table. deleteKeywords() Deletes keywords for the given contact. It takes contact ID as the parameter. 306 Part II: Developing Intranet Solutions 12 549669 ch09.qxd 4/4/03 9:25 AM Page 306 Method Description modifyKeywords() Updates keyword information for the given contact. It uses deleteKeywords() to delete the previous keywords, and then uses addKeywords() to add the new keywords. This method takes the contact ID and the new keywords array as parameters. setContactID() Sets the contact ID. If the contact ID is passed to this method, it sets the member variable cid to the given contact ID. At the end it returns the contact ID. getColumnValue() Returns the value of the given column from the database for the current contact object. It takes the column name as a parameter. This method uses loadContactInfo() with the given contact ID to set all the attributes for the contact, and then returns the formatted value of the specified column. deleteRemindersByContactID() Deletes all reminders from the reminder table for a given contact ID. It takes the contact ID as the input and returns TRUE or FALSE, depending on the deletion status. deleteKeywordsByContactID() Deletes all keywords from the keyword table for a given contact ID. So it takes contact ID as the input and returns TRUE or FALSE, depending on the deletion status. addReminder() Adds new reminders to the reminder table for the given contact. It takes the contact ID, author ID, the remind note, the publish date, and the message ID as a parameter. Then it returns TRUE or FALSE, depending on the status of the operation. storeMail() Stores new mail in the database. Attributes such as contact ID, CC To, subject, body, and send time stamp are passed as parameters to this method. replaceCategory() Replaces the old category with the given new one. It takes the old and new category IDs as parameters and returns TRUE or FALSE, depending on the status of the operation. getMailDetails() Returns detailed information of the given mail ID. It takes the mail ID as a parameter and returns the details of it. Chapter 9: Intranet Contact Manager 307 12 549669 ch09.qxd 4/4/03 9:25 AM Page 307 The Application Configuration Files Like all other applications we’ve developed in this book, the intranet contact man- ager applications also use a standard set of configuration, message, and error files. These files are discussed in the following sections. The main configuration file The primary configuration file for the contact manager is called contact.conf. Table 9-2 discusses each configuration variable. TABLE 9-2 THE CONTACT.CONF VARIABLES Variable Purpose $PEAR_DIR Set to the directory containing the PEAR package; specifically the DB module needed for class.DBI.php in our application framework. $PHPLIB_DIR Set to the PHPLIB directory, which contains the PHPLIB packages; specifically the template.inc package needed for template manipulation. $APP_FRAMEWORK_DIR Set to our application framework directory. $PATH Set to the combined directory path consisting of the $PEAR_DIR, the $PHPLIB_DIR, and the $APP_FRAMEWORK_DIR. This path is used with the ini_set() method to redefine the php.ini entry for include_path to include $PATH ahead of the default path. This allows PHP to find our application framework, PHPLIB, and PEAR-related files. $AUTHENTICATION_URL Set to the central login application URL. $LOGOUT_URL Set to the central logout application URL. $HOME_URL Set to the top-most URL of the site. If the URL redirection application does not find a valid URL in the e-campaign database to redirect to for a valid request, it uses this URL as a default. $APPLICATION_NAME Internal name of the application. $DEFAULT_LANGUAGE Set to the default two-character language code. 308 Part II: Developing Intranet Solutions 12 549669 ch09.qxd 4/4/03 9:25 AM Page 308 Variable Purpose $ROOT_PATH Set to the root path of the application. $REL_ROOT_PATH Relative path to the root directory. $REL_APP_PATH Relative application path as seen from the web browser. $TEMPLATE_DIR The fully qualified path to the template directory. $THEME_TEMPLATE_DIR The fully qualified path to the theme template directory. $REL_PHOTO_DIR The Web-relative path to the photo directory used to store user photos. $PHOTO_DIR The fully qualified path to the photo directory. $DEFAULT_PHOTO Name of the default photo file, which is used when a user does not have a photo in the photo directory. $CLASS_DIR The fully qualified path to the class directory. $REL_TEMPLATE_DIR The Web-relative path to the template directory used. $CATEGORY_CLASS Name of the Category class file. $CONTACT_CLASS Name of the Contact class file. $MESSAGE_CLASS Name of the Message class file. This class was developed for the MOTD application discussed in Chapter 8. $CONTACT_MNGR Name of the application that shows the index page of the application with the contact search menu. $CONTACT_CAT_MNGR Name of the application that manipulates all functions related to contact category. $INTRANET_DB_URL The fully qualified URL for the database used to MOTD information. $CONTACT_DB_URL The fully qualified URL for the database used to store the contacts and categories. Continued Chapter 9: Intranet Contact Manager 309 12 549669 ch09.qxd 4/4/03 9:25 AM Page 309 TABLE 9-2 THE CONTACT.CONF VARIABLES (Continued) Variable Purpose $CONTACT_CATEGORY_TBL Name of the category table in the database. $CONTACT_INFO_TBL Name of the contact info table in the database. $CONTACT_KEYWORD_TBL Name of the contact keyword table in the database. $USER_PREFERENCE_TBL Name of the user preference table in the intranet database. $MESSAGE_TBL Name of the MOTD message table in the intranet database. $CONTACT_MAIL_TBL Name of the contact mail table in the database. $MSG_VIEWER_TBL Name of the message viewer list table in the intranet database. $AUTH_DB_TBL Name of the user authentication table in the auth database. $STATUS_TEMPLATE Name of the status template file used to display status messages. $CONTACT_HOME_TEMPLATE Name of the contact index template file. $CONTACT_CAT_HOME_TEMPLATE Name of the contact category index template file. $CONTACT_INFO_ADD_MOD_TEMPLATE Name of the add/modify contact entry form template file. $CONTACT_CAT_ADD_MOD_TEMPLATE Name of the add/modify category entry form template file. $CONTACT_DETAILS_TEMPLATE Name of the contact details template file. ODD_COLOR Color defined for odd rows when displaying tabular data. EVEN_COLOR Color defined for even rows when displaying tabular data. USER_DB_URL The fully qualified authentication database URL. 310 Part II: Developing Intranet Solutions 12 549669 ch09.qxd 4/4/03 9:25 AM Page 310 . specifically the DB module needed for class.DBI .php in our application framework. $PHPLIB_DIR Set to the PHPLIB directory, which contains the PHPLIB packages; specifically the template.inc package. $PHPLIB_DIR, and the $APP_FRAMEWORK_DIR. This path is used with the ini_set() method to redefine the php. ini entry for include_path to include $PATH ahead of the default path. This allows PHP. to include $PATH ahead of the default path. This allows PHP to find our application framework, PHPLIB, and PEAR-related files. $AUTHENTICATION_URL Set to the central login application URL. $LOGOUT_URL