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
Configuration Variable Purpose $USER_PREFERENCE_TBL Name of the user preference table in the database. $MESSAGE_TBL Name of the MOTD message table in the database. $IRM_RESOURCE_VISITOR Name of the resource visitor table in the database. $MSG_VIEWER_TBL Name of the message viewer list table in the database. $AUTH_DB_TBL Name of the user authentication table in the database. $IRM_RESOURCE_ Name of the resource description template file. DES_TEMPLATE $IRM_RESOURCE_ Name of the resource menu template file. MENU_TEMPLATE $IRM_RESOURCE_MODIFY_ Name of the resource modify form template file. MENU_TEMPLATE $IRM_MOTD_TEMPLATE Name of the live note template file. $IRM_CAT_HOME_TEMPLATE Name of the category index template file. $IRM_CAT_ADD_MODTEMPLATE Name of the add/modify category entry form template file. $IRM_SEARCH_RESULT_ Name of the search result showing template file. TEMPLATE $IRM_SEARCH_TEMPLATE Name of the resource searching template file. $IRM_STATUS_TEMPLATE Name of the status template file used to display status messages. ODD_COLOR Color defined for odd rows when displaying tabular data such as document track listing. EVEN_COLOR Color defined for even rows when displaying tabular data such as document track listing. $RATINGS Defines an associative array used to display response rating information. USER_DB_URL The fully qualified authentication database URL. CAT_PER_LINE’ Number of categories per row to show in a navigation table, which is created in the navigation file. Continued Chapter 11: Internet Resource Manager 371 14 549669 ch11.qxd 4/4/03 9:25 AM Page 371 TABLE 11-1 IRM.CONF VARIABLES (Continued) Configuration Variable Purpose SEPARATOR The characters that separate each navigation entry (category) in the navigation, which is created in the navigation file. $DEFAULT_THEME The default theme index in the $THEME_TEMPLATE array. $USER_DEFAULTS A user’s theme and auto tip default settings. $TIP_SCRIPT The name of the tip script. $TIP_URL The Web-relative path for the tip files. $MAX_AVAILABLE_TIP The maximum number of tips from which to display the tip. $THEME_TEMPLATE[x] The list of theme templates. $PRINT_TEMPLATE[x] The list of print templates associative with the theme templates. The directory structure used in the irm.conf file supplied in the ch11 directory on the CD-ROM might need to be tailored to your own system’s requirements. Here is how the current directory structure looks: htdocs ($ROOT_PATH = %DocumentRoot%) | + home (base intranet application discussed in chapter 7) | | | + templates (templates used by intranet apps) | | | + themes (theme templates used by all intranet apps) | + photos (user photos used by all intranet apps) | + irm (IRM Applications) | + apps (IRM apps and configuration files) | + class (IRM classes) | 372 Part II: Developing Intranet Solutions 14 549669 ch11.qxd 4/4/03 9:25 AM Page 372 + templates (IRM HTML templates) | + themes (symlink to %DocumentRoot%/home/templates/themes) By changing the following configuration parameters in irm.conf, you can mod- ify the directory structure to fit your site requirements: $PEAR_DIR = $_SERVER[‘DOCUMENT_ROOT’] . ‘/pear’ ; $PHPLIB_DIR = $_SERVER[‘DOCUMENT_ROOT’] . ‘/phplib’; $APP_FRAMEWORK_DIR = $_SERVER[‘DOCUMENT_ROOT’] . ‘/framework2’; $PATH = $PEAR_DIR . ‘:’ . $PHPLIB_DIR . ‘:’ . $APP_FRAMEWORK_DIR; $ROOT_PATH = $_SERVER[‘DOCUMENT_ROOT’]; $REL_ROOT_PATH = ‘/irm’; $REL_APP_PATH = $REL_ROOT_PATH . ‘/apps’; $TEMPLATE_DIR = $ROOT_PATH . $REL_APP_PATH . ‘/templates’; $CLASS_DIR = $ROOT_PATH . $REL_APP_PATH . ‘/class’; $THEME_TEMPLATE_DIR = $TEMPLATE_DIR . ‘/themes’; $REL_PHOTO_DIR = ‘/photos’; $PHOTO_DIR = $ROOT_PATH . $REL_PHOTO_DIR; Creating a messages file The messages displayed by the IRM applications are stored in the ch11/apps/ calendar.messages file in the CDROM. You can change the messages using a text editor. Creating an errors file The error messages displayed by the IRM applications are stored in the /ch11/ apps/calendar.errors file in the CDROM. You can modify the error messages using a text editor. Creating Application Templates The HTML interface templates needed for the applications are included in the ch11/apps/templates directory in the CD-ROM. These templates contain vari- ous template tags to display necessary information dynamically. The templates are named in the irm.conf file. These templates are discussed in Table 11-2. Chapter 11: Internet Resource Manager 373 14 549669 ch11.qxd 4/4/03 9:25 AM Page 373 TABLE 11-2 HTML TEMPLATES Configuration Variable Template File Purpose $IRM_STATUS_TEMPLATE irm_status.html This template is used to show status message. $IRM_RESOURCE_ irm_resource_des.html This template is used to DES_TEMPLATE display resource description. $IRM_RESOURCE_ irm_resource_mngr.html This is the template used MENU_TEMPLATE to show/create resources. $IRM_RESOURCE_MODIFY_ irm_resource_modify_ This is the Web form MENU_TEMPLATE mngr.html template to modify resource information. $IRM_CAT_HOME_TEMPLATE irm_cat_home.html This is the category index template. $IRM_CAT_ADD_ irm_cat_add_mod.html This is the Web form MODTEMPLATE template to add or modify a category. $IRM_SEARCH_ irm_search_result.html This template is used to RESULT_TEMPLATE show search results. $IRM_SEARCH_TEMPLATE irm_search.html This template is used to show search options. $IRM_MOTD_TEMPLATE irm_motd.html This template is used to generate the live note message. Creating a Category Manager Application This application, irm_cat_mngr.php, is responsible for managing categories. This application is included on the CD-ROM in the ch11/apps directory. It implements the following functionality: ◆ Allows administrative users to create, modify, and delete categories. ◆ Allows non-administrative users to create categories. Non-administrative users cannot modify or delete categories. 374 Part II: Developing Intranet Solutions 14 549669 ch11.qxd 4/4/03 9:25 AM Page 374 The ch11/apps/irm_cat_mngr.php in the CDROM is an implementaiton of this application. This application has the following methods. run() When the application is run, this method is called. It does the following: ◆ Creates a theme object, $this->themeObj. ◆ The current user’s theme choice is stored in $this->theme by calling the getUserTheme() method of the theme object created. ◆ Next, if the application is called with cmd set to add query parameter, the addDriver() method starts running. If cmd is set to modify then the modifyDriver() method is called. Similarly, if cmd is set to delete then it invokes deleteCategory() method. If the cmd is set to null then it calls the showMenu() method. In other words, the run() method decides which functionality is requested by the user and calls the appropriate driver method to perform the desired operations. addDriver() This method controls how add operations are performed on categories. It works as follows: ◆ If step is set to 1 in the query parameter when the application is called, this method calls the displayAddCategoryMenu() method to show the category creation options. ◆ If step is set to 2 in the query parameter when this application is called, this method runs the addCategory() method to add the new category. modifyDriver() This method controls how modify operations are performed on categories. It works as follows: ◆ If step, query parameter, is set to 1, then it calls the displayModifyCategoryMenu() method to show the category modification options. ◆ If step, query parameter, is set to 2, then it runs the modifyCategory() method to start the category modification process. addCategory() This method adds new category to the database. It works as follows: Chapter 11: Internet Resource Manager 375 14 549669 ch11.qxd 4/4/03 9:25 AM Page 375 . $_SERVER[‘DOCUMENT_ROOT’] . ‘/pear’ ; $PHPLIB_DIR = $_SERVER[‘DOCUMENT_ROOT’] . ‘/phplib’; $APP_FRAMEWORK_DIR = $_SERVER[‘DOCUMENT_ROOT’] . ‘/framework2’; $PATH = $PEAR_DIR . ‘:’ . $PHPLIB_DIR . ‘:’ . $APP_FRAMEWORK_DIR; $ROOT_PATH. the live note message. Creating a Category Manager Application This application, irm_cat_mngr .php, is responsible for managing categories. This application is included on the CD-ROM in the ch11/apps. Developing Intranet Solutions 14 549669 ch11.qxd 4/4/03 9:25 AM Page 374 The ch11/apps/irm_cat_mngr .php in the CDROM is an implementaiton of this application. This application has the following methods. run() When