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
This configuration file creates a multidimensional array called $ERRORS and sets two error codes to appropriate error messages in U.S. English. If the sample appli- cation is to be used in a different language region, say in Spain, then this file can be modified to create the ES (shorthand for Spanish) language-specific errors by replacing US as ES and also translating the actual error messages. When internationalizing the error messages, the error code such as UNAUTHORIZED_ACCESS should not be translated because that code name is the key to locate the “Unauthorized access” error message. Only the error message should be translated, and the appropriate language identifier needs to be set. The sample application then loads the sample.messages file, which is shown in Listing 4-8. Listing 4-8: sample.messages <?php $MESSAGES[‘US’][‘APP_FAILED’] = “Application Failed.”; $MESSAGES[‘US’][‘DEFAULT_MSG’] = “Hello World”; ?> Like the error message files, this file loads a multidimensional array called $MESSAGES with language support for each message. The sample.conf file also loads the constants.php file, which defines a set of constants needed by the framework classes. The same sample configuration file also loads the framework classes along with a class called class.sampleApp.php, which is shown in Listing 4-9. This class extends the PHPApplication class and overrides the run() and authorize() function. It implements another function called doSomething(), which is specific to itself. We will discuss the details of this class in the next sec- tion. Now let’s look at the rest of the sample.php code. Once the class.sampleApp.php class is loaded, the session is automatically started by the sampleApp object, which extends the PHPApplication object. Next the application creates an instance of the sampleApp object called $thisApp. This is the application object. The application name, version, type, and debugger ON or OFF flag are set when creating this object. 116 Part II: Developing Intranet Solutions 07 549669 ch04.qxd 4/4/03 9:24 AM Page 116 After the $thisApp object has been created, the sample application enables debug message buffering by calling the buffer_debugging() method in class. PHPApplication.php class. It then calls the run() function, which has been overridden in class. sampleApp.php . This is the main function that runs the application. After the application has run, more debugging information is buffered and the debug information is dumped: $thisApp->buffer_debugging(); $thisApp->run(); $thisApp->debug(“Version : “ . $thisApp->get_version()); $thisApp->dump_debuginfo(); Figure 4-6 shows what is displayed when the sample.php application is run after a user has already logged in. Figure 4-6: Output of the sample application with debugging turned on. You have to have the application framework created in this chapter installed on your system and at least one user created to run this application.To learn about how to create a user, see Chapter 5. Chapter 4: Architecture of an Intranet Application 117 07 549669 ch04.qxd 4/4/03 9:24 AM Page 117 Figure 4-7 shows the application with the debug flag turned off. Figure 4-7: Output of the sample application with debugging turned off. Listing 4-9 shows the class.sampleApp.php, which extends the PHPApplication class from our framework. Listing 4-9: class.sampleApp.php <?php class sampleApp extends PHPApplication { function run() { // At this point user is authorized // Start business logic driver $this->debug(“Real application code starts here.”); $this->debug(“Call application specific function here.”); $this->doSomething(); } function authorize($email = null) { return TRUE; } function doSomething() { global $MESSAGES, $DEFAULT_LANGUAGE; 118 Part II: Developing Intranet Solutions 07 549669 ch04.qxd 4/4/03 9:24 AM Page 118 $this->debug(“Started doSomething()”); echo $MESSAGES[$DEFAULT_LANGUAGE][‘DEFAULT_MSG’]; $this->debug(“Finished doSomething()”); } } // Class ?> This sampleApp class has only three functions: run(), authorize(), and doSomething(). The run() function overrides the abstract run() method provided in class.PHPApplication.php and it is automatically called when the application is run. Therefore, sampleApp run() method is needed to application logic in sample.php. In the example, the authorization check always returns TRUE, because this isn’t a real-world application and the run() function calls the doSomething() function, which simply prints a set of debug messages along with a status message. Notice that although the application status message $MESSAGES[$DEFAULT_LANGUAGE] [‘DEFAULT_MSG’] is internationalized, the debug messages are in English. As you can see the application framework makes writing new applications quite easy; development time is greatly reduced, because you can build onto the frame- work instead of starting from scratch every time. Summary In this chapter I have shown you how to develop a complete application framework consisting of a few object-oriented classes. These classes provide a set of facilities for writing applications that use a standard approach to writing PHP applications for both intranet and the Web. The application framework developed in this chapter allows you to develop a new application by simply extending the primary class, PHPApplication class, of the framework. Immediately your application inherits all the benefits of the new framework, which includes a database abstraction, an error handler, and a debug- ging facility. This application framework is used throughout the rest of the book for develop- ing most of the applications discussed in this book. The latest version of this frame- work is always available from http://www.evoknow.com/phpbook/. Chapter 4: Architecture of an Intranet Application 119 07 549669 ch04.qxd 4/4/03 9:24 AM Page 119 07 549669 ch04.qxd 4/4/03 9:24 AM Page 120 . 4-9 shows the class.sampleApp .php, which extends the PHPApplication class from our framework. Listing 4-9: class.sampleApp .php < ?php class sampleApp extends PHPApplication { function run() { //. calling the buffer_debugging() method in class. PHPApplication .php class. It then calls the run() function, which has been overridden in class. sampleApp .php . This is the main function that runs the. look at the rest of the sample .php code. Once the class.sampleApp .php class is loaded, the session is automatically started by the sampleApp object, which extends the PHPApplication object. Next