1. Trang chủ
  2. » Công Nghệ Thông Tin

Secure PHP Development- P28 docx

5 240 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Secure PHP Development

    • Front Matter

      • Preface

        • Is This Book for You?

        • How This Book Is Organized

        • Tell Us What You Think

      • Acknowledgments

      • Contents at a Glance

      • Contents

    • Part I

      • Chapter 1: Features of Practical PHP Applications

        • Features of a Practical PHP Application

        • Employing the Features in Applications

        • Summary

      • 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

Listing 4-4 (Continued) function setDefault($value, $default) { return (isset($value)) ? $value : $default; } function fileextension($filename) { return substr(basename($filename), strrpos(basename($filename), “.”) + 1); } function outputTemplate(&$t) { $t->parse(‘main’, ‘mainBlock’, false); return $t->parse(‘output’, ‘fh’); } function showScreen($templateFile = null, $func = null, $app_name) { $menuTemplate = new Template($this->getTemplateDir()); $this->doCommonTemplateWork($menuTemplate, $templateFile, $app_name); if ($func != null) { $status = $this->$func($menuTemplate); } if ($status) { return $this->outputTemplate($menuTemplate); } else { return null; } } function doCommonTemplateWork(&$t, $templateFile, $app_name) { 106 Part II: Developing Intranet Solutions 07 549669 ch04.qxd 4/4/03 9:24 AM Page 106 $t->set_file(‘fh’, $templateFile); $t->set_block(‘fh’,’mainBlock’, ‘main’); $t->set_var(array( ‘APP_PATH’ => $this->getAppPath(), ‘APP_NAME’ => $app_name, ‘BASE_URL’ => $this->getBaseURL() ) ); } function getEnvironment($key) { return $_SERVER[$key]; } function showPage($contents = null) { global $THEME_TEMPLATE; global $THEME_TEMPLATE_DIR, $REL_TEMPLATE_DIR; global $REL_TEMPLATE_DIR; global $PHOTO_DIR, $DEFAULT_PHOTO, $REL_PHOTO_DIR; $themeObj = new Theme($this->dbi, null,’home’); $this->themeObj = $themeObj; $this->theme = $themeObj->getUserTheme($this->getUID()); $themeTemplate = new Template($THEME_TEMPLATE_DIR); $themeTemplate->set_file(‘fh’, $THEME_TEMPLATE[$this->theme]); $themeTemplate->set_block(‘fh’, ‘mmainBlock’, ‘mmblock’); $themeTemplate->set_block(‘mmainBlock’, ‘contentBlock’, ‘cnblock’); $themeTemplate->set_block(‘mmainBlock’, ‘printBlock’, ‘prnblock’); $themeTemplate->set_var(‘printBlock’, ‘ ’); $themeTemplate->parse(‘prnblock’, ‘printBlock’,false); $themeTemplate->set_block(‘mmainBlock’, ‘pageBlock’, ‘pblock’); $themeTemplate->set_var(‘pblock’, null); $photoFile = sprintf(“%s/photo%003d.jpg”,$PHOTO_DIR, $this->getUID()); $defaultPhoto = sprintf(“%s/%s”,$REL_PHOTO_DIR,$DEFAULT_PHOTO); $userPhoto = sprintf(“%s/photo%003d.jpg”,$REL_PHOTO_DIR,$this->getUID()); $photo = file_exists($photoFile) ? $userPhoto : $defaultPhoto; Continued Chapter 4: Architecture of an Intranet Application 107 07 549669 ch04.qxd 4/4/03 9:24 AM Page 107 Listing 4-4 (Continued) $themeTemplate->set_var(‘PHOTO’, $photo); $themeTemplate->set_var(‘TEMPLATE_DIR’, $REL_TEMPLATE_DIR); $themeDir = $THEME_TEMPLATE_DIR . ‘/’ . dirname($THEME_TEMPLATE[$this- >theme]); $leftNavigation = $this->themeObj->getLeftNavigation($themeDir); $themeTemplate->set_var(‘LEFT_NAVIGATION’, $leftNavigation); $themeTemplate->set_var(‘SERVER_NAME’, $this->get_server()); $themeTemplate->set_var(‘BASE_HREF’, $REL_TEMPLATE_DIR); $themeTemplate->set_var(‘CONTENT_BLOCK’, $contents); $themeTemplate->parse(‘cnblock’, ‘contentBlock’); $themeTemplate->parse(‘mmblock’, ‘mmainBlock’); $themeTemplate->pparse(‘output’, ‘fh’); } } ?> The methods in the class.PHPApplication.php class, which implements the base application in our framework, are discussed in detail in Table 4-1. TABLE 4-1 METHODS IN CLASS.PHPAPPLICATION.PHP Function Description PHPApplication() The constructor function for PHPApplication (class.PHPApplication.php) class. Sets app_name, app_version, app_type, debug_mode, error, authorized, and has_error member variables. If debug_mode is set to $ON (1), a debugger object called debugger is created. It also creates an error handler from ErrorHandler class. The constructor starts the session using session_start(), and also sets self_url by calling set_url(). check_session() Checks if the session username variable is set, or calls the reauthenticate() function method. 108 Part II: Developing Intranet Solutions 07 549669 ch04.qxd 4/4/03 9:24 AM Page 108 Function Description reauthenticate() Redirects the application user to the authentication application pointed by the global $AUTHENTICATION_URL variable. set_url() Creates a URL that points to the application itself. terminate() Terminates the application. If the application is connected to a database, the database connection is first closed and then the application session is destroyed. authorize() A blank authorized function method that should be overridden by the application. The abstract application object cannot authorize access to the application itself. set_error_handler() Creates an error handler object and stores the object in errHandler member variable. alert() Calls the alert function method from the ErrorHandler class. get_error_message() Gets the error message from the ErrorHandler class. show_debugger_banner() Displays the debug banner if debugging is enabled. (The banner display is done by the debugger class.) buffer_debugging() Sets the debug message buffering in the built-in Debugger object if the debugging is turned on. dump_debuginfo() Flushes the debug buffer if debugging was turned on. debug() Provides a wrapper for the write() method in the built- in debugger. run() Should be overridden by the instance of the PHPApplication to run it. connect() Creates a DBI object and connects the application to the desired relational database. disconnect() Disconnects the application from the database. get_error_message() Returns the error message for a given error code (calls the get_error_message of the ErrorHandler). show_debugger_banner() Prints the debugger banner if debugging is turned on. buffer_debugging() Enables you to buffer debugging so that it can be printed later. Continued Chapter 4: Architecture of an Intranet Application 109 07 549669 ch04.qxd 4/4/03 9:24 AM Page 109 TABLE 4-1 METHODS IN CLASS.PHPAPPLICATION.PHP (Continued) Function Description dump_debuginfo() Dumps all debug information if it was buffered in the built-in debugger object. debug() Writes the debug message using the debugger object’s write() function method. run() A dummy function method that must be overridden by each application to run the application. An application usually has its business logic driver in this method. connect() Creates a DBI object and connects the application to a given database. The database URL is passed as a parameter, and the DBI object is stored as a member variable called dbi in the PHPApplication class. disconnect() Disconnects the database connection for the application by calling the DBI disconnect()method. get_version() Returns the version of the application. The version is supplied as a parameter during PHPApplication object creation. get_name() Returns the name of the application (supplied as a parameter during PHPApplication object creation). get_type() Returns the type of the application (supplied as a parameter during PHPApplication object creation). set_error() Sets error code for the application and also sets the has_error flag to TRUE. (When used to set error code, the error codes are stored in an array called error.) When application needs to generate an error message, you use this function method to set the error code first, and then call get_error_message(). has_error() Returns TRUE if the application has error(s); otherwise it returns FALSE. reset_error() Resets has_error flag to FALSE. get_error() Returns an error code from the error array. get_error_array() Returns the entire error code array. You can get the error code array and use the get_error_message() method to return the appropriate error messages. 110 Part II: Developing Intranet Solutions 07 549669 ch04.qxd 4/4/03 9:24 AM Page 110 . class.PHPApplication .php class, which implements the base application in our framework, are discussed in detail in Table 4-1. TABLE 4-1 METHODS IN CLASS.PHPAPPLICATION .PHP Function Description PHPApplication(). CLASS.PHPAPPLICATION .PHP Function Description PHPApplication() The constructor function for PHPApplication (class.PHPApplication .php) class. Sets app_name, app_version, app_type, debug_mode, error, authorized,. Intranet Application 109 07 549669 ch04.qxd 4/4/03 9:24 AM Page 109 TABLE 4-1 METHODS IN CLASS.PHPAPPLICATION .PHP (Continued) Function Description dump_debuginfo() Dumps all debug information if it

Ngày đăng: 07/07/2014, 07:20