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
addKeywords() This method inserts keywords in the RESOURCE_KEYWORD table. This method is called with resource ID ($rid) and an array ($params), which contains the keywords. Each keyword is inserted into the table using a foreach loop. It returns TRUE if it adds keywords successfully; otherwise, it returns FALSE. deleteKeywords() This method deletes all the keywords for the given resource from the database. This method is called with the resource ID ($rid). It returns TRUE if it successfully deletes all the keywords; otherwise, it returns FALSE. getKeywords() This method returns keyword(s) for the given resource. It works as follows: ◆ This method is called with the resource ID ($rid). ◆ A SQL statement, $stmt, is created which queries the RESOURCE_KEYWORD table for all keywords for the given resource ID. ◆ The SQL statement is executed using the $this->dbi->query() method and the result of the query is stored in the $result object. ◆ If no rows are returned in the $result object, the method returns null. ◆ On the other hand, it fetches the $result object and each row is stored in the $row object and the keyword is stored in the $retArr array. Then the array $retArr is returned. searchResource() This method searches resource in the RESOURCE table. This method works as follows: ◆ This method is called with an associative array ($params), which contains search criteria. ◆ If the resource category ($params[RESOURCE_CATEGORY]) is provided in the parameter, then the method checks whether the given category is the main category or not. If it is the main category, then it generates SQL conditions for each subcategory of the given category along with the main category. On the other hand, it generates the SQL condition only for the main category. These conditions are stored in a variable called $category. ◆ Then It checks whether the rating $params[RESOURCE_RATING] criteria is provided or not. If the rating criteria is provided, then the SQL condition is generated and stored in a variable called $rating. ◆ If the resource added by criteria $params[RESOURCE_ADDED_BY] is given, then it generates the SQL condition for the resources, which is added by a particular user. 366 Part II: Developing Intranet Solutions 14 549669 ch11.qxd 4/4/03 9:25 AM Page 366 ◆ If the resource visited by criteria $params[RESOURCE_VISITED_BY] is given, then it generates the SQL condition for the resources, which is visited by a particular user. ◆ Next This method checks whether the keywords are provided for searching or not. If they are provided, then it generates the SQL condition that will search for resources that have the given keywords. ◆ A SQL statement, $stmt, is created which queries for the resources falling under all the given criterion. ◆ The SQL statement is executed using the $this->dbi->query() method and the result of the query is stored in the $result object. ◆ If no rows are returned in the $result object, the method returns null. ◆ On the other hand, it fetches the $result object and each row is stored in the $row object and the $row object is stored in the $retArr array. Then the array $retArr is returned. modifyResource() This method updates existing resource information in the database. It works as follows: ◆ The method is called with an associative array ($params), which contains the fields name of the RESOURCE table, its new value, and the resource ID ($resource_id) for which it will update. ◆ The given resource title ($params[RESOURCE_TITLE]), resource location ($params[RESOURCE_LOCATION]), and resource description ($params[RESOURCE_DESCRIPTION] ) are escaped for characters such as quotation marks and slashes using $this->dbi->quote(addslashes()) methods. ◆ A SQL statement, $statement, is created to update the new resource data into the RESOURCE table. ◆ The SQL statement is executed using the $this->dbi->query() method and the result of the query is stored in the $result object. ◆ If the resource is successfully updated, then this method returns TRUE; otherwise, it returns FALSE. trackResourceVisit() When a user clicks on a URL for a resource displayed in a category or as a search result, the URL click event is tracked. This method is responsible for inserting a track record in the RESOURCE_TRACK table for such URL clicks. Chapter 11: Internet Resource Manager 367 14 549669 ch11.qxd 4/4/03 9:25 AM Page 367 deleteResource() This method deletes a resource from RESOURCE table of the database. It deletes a resource by the given resource ID ($rid). getNumOfResourceInCat() This method returns the number of resources that reside in the given category. This method is called with a category ID ($catID) as parameter. getResourceByCategory() This method returns all the resources that fall under the given category. This method is called with a category ID ($catID). getResourceUrl() This method returns URL of the resource. This method is called with a resource ID ($rid). getTotalResourceNum() This method returns the total number of resources in the RESOURCE table. getResourceInfo() This method returns information related to the given resource. This method is called with resource ID ($rid). getNewResource() This method returns the number of newly added resources. This method is called with category ID ($catid) and time limit ($timeLimit). It finds the number of the resources that fall under the given category ID and are added after the given time limit. getTopRankingList() This method returns the top-ranking resource list. This method is called with a parameter that can be considered as the lower bound of the top ranking list (that is, this method finds all the resources that have ranking higher than or equal to this parameter). It returns an associative array, which contain the resource ID and its information. Designing and implementing the Message class The Message class is used to manipulate each message. It allows an application to create and delete messages. This class is discussed in Chapter 7. 368 Part II: Developing Intranet Solutions 14 549669 ch11.qxd 4/4/03 9:25 AM Page 368 Creating Application Configuration Files Like all other applications we’ve developed in this book, the Internet Resource Manager applications also use a standard set of configuration, message, and error files. These files are discussed in the following sections. Creating the main configuration file The primary configuration file for the entire Internet Resource Manager is called irm.conf. Table 11-1 discusses each configuration variables. TABLE 11-1 IRM.CONF VARIABLES Configuration 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, $PHPLIB_DIR, and $ 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 topmost URL of the site. If the URL redirection application doesn’t 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 The internal name of the application. Continued Chapter 11: Internet Resource Manager 369 14 549669 ch11.qxd 4/4/03 9:25 AM Page 369 TABLE 11-1 IRM.CONF VARIABLES (Continued) Configuration Variable Purpose $DEFAULT_LANGUAGE Set to the default (two characters) language code. $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 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. $IRM_CATEGORY_CLASS Name of the Category class file. $IRM_RESOURCE_CLASS Name of the Resource class file. $IRM_MESSAGE_CLASS Name of the Message class file. This class is developed for the MOTD application discussed in Chapter 10. $IRM_RESOURCE_MNGR Name of the application that manages resources. $IRM_SEARCH_MNGR Name of the application that is used to search for resources. $IRM_RESOURCE_TRACK_MNGR Name of the application that tracks user visits to resources. $IRM_CAT_MNGR Name of the application that manages categories. $IRM_DB_URL The fully qualified URL for the database used to store the resources and categories. $IRM_CATEGORY_TBL Name of the category table in the database. $IRM_RESOURCE_TBL Name of the resource table in the database. $IRM_RESOURCE_KEYWORD_TBL Name of the resource keyword table in the database. 370 Part II: Developing Intranet Solutions 14 549669 ch11.qxd 4/4/03 9:25 AM Page 370 . 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. $PEAR_DIR, $PHPLIB_DIR, and $ 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