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

Secure PHP Development- P89 pptx

5 114 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

◆ If no keyword is passed as a parameter to the method, it returns FALSE. ◆ If the keywords have been supplied, it reads the recent search history as a hash in $hash using the getRecentSearchList() method. The getRecentSearchList() is called with TRUE as a $asis parameter so that it returns the search history as an unmodified hash. ◆ If the current keywords already exist in $hash, then the method returns FALSE since there is no need to add duplicate keywords in the history. ◆ If the current history does not exceed the SEARCH_HISTORY_SIZE size specified in the configuration file (help.conf), then the current keywords are inserted into the a new hash called $outHash along with the existing history data. ◆ Finally, the new $outHash is written to the history file using the writeSearchHistory() method, and the method returns TRUE. getKeywordMatch() This method checks to see whether the given keyword ($keyword) exists in the key- word index of the given sections ($sections) and returns the matching section list. It works as follows: ◆ The given keyword is lowercased because the keyword index stores all keywords in lowercase format. ◆ A list called $matchedSections is initialized as an empty array. ◆ For each given section, the given keyword is searched in the keyword index cache stored in the keyword index file. ◆ In the loop, for each given section, a keyword index cache file called $keywordCacheFile is set using the getKeywordFile() method. ◆ A hash object (that is, keyword index cache) called $cache is loaded using the readKeywordCacheFile() method. ◆ If the current keyword is found in the $cache object, the current section is stored in $matchedSections. ◆ Finally, the matched section list is returned. getSectionNumberList() This method returns the section numbers from the current section hash. getSectionHash() This method returns a hash that has section numbers as keys and section names as values. If a section list is given, the method only returns the hash for the given sec- tion list. Otherwise, it returns the entire list of sections for the current help contents. Chapter 12: Online Help System 411 15 549669 ch12.qxd 4/4/03 9:26 AM Page 411 getSectionList() This method returns the list of sections. getKeywordString() This method creates a string out of the list of keywords and returns the string. getKeywordList() This method sets the object variable _KEYWORDS with given keywords. However, it removes duplicates and any instance of the word ‘or’. The ‘or’ operator is implied automatically when multiple keywords exist in the keyword list and, therefore, it is removed. getSections() This method returns the section hash stored in the object variable _SECTIONS. getHelpDir() This method returns the help directory path stored in _HELP_DIR. If _HELP_DIR is empty, it returns null. makeKeywordIndex() This method creates the keyword index cache object for a given section and stores the cache as a serialized hash object in a file. It works as follows: ◆ First, it creates a local variable called $helpFile that is set to the fully qualified pathname of the given section’s ($section) help file returned by the getFQPNofSection() method. ◆ If the help file (that is, the help contents) does not exist for the current section, the method returns FALSE. ◆ If the help file exists, a local variable called $keywordCacheFile is set to the fully qualified pathname of the current section’s keyword index cache file returned by the getKeywordFile() method. ◆ If this keyword index cache exists, the help file’s modification time ($helpFileModifyTimeStamp) is compared with the modification time ($keywordIndexCreateTimeStamp) of the keyword index. If the help file modification time is older than the keyword index file modification time, the keyword index is up to date and therefore not needed to be re-created, unless the object variable _FORCE is set to true. When the keyword index is up to date and the index doesn’t need to be forcefully re-created, the method returns TRUE, indicating that index creation was a success. ◆ On the other hand, if the keyword index doesn’t exist or the modification time of the help file is newer than the existing keyword index file, then the method must continue and create the index cache from the help contents. 412 Part II: Developing Intranet Solutions 15 549669 ch12.qxd 4/4/03 9:26 AM Page 412 ◆ The _getWords() is called with the help file ($helpFile) and the returned word list is stored in the $words variable. ◆ The _removeExcludedWords() method is called with the $words to remove words that need to be excluded. The words are compared to words stored in the EXCLUDED_WORD_FILE file and matching words are removed from the $words list. ◆ The resulting $words list and the $keywordCacheFile file name are passed as a parameter to the writeKeywordCacheFile() method to write the cache file. ◆ If the file is written successfully, the method returns TRUE; otherwise, it returns FALSE. getFQPNSearchHistoryFile() This method returns the fully qualified search history file name. getFQPNofSection() This method returns the fully qualified section file name. getHelpTemplateDir() This method returns the fully qualified help template directory path. getDefaultSectionTemplate() This method returns the default section template path. getTOCTempalte() This method returns the table of contents template path. getSearchResultTempalte() This method returns the search result template path. getSectionTemplate() This method returns the template path for a given section if it exists; otherwise, it returns the default section template path. getBaseURL() This method returns the base URL. loadMap() This method loads the help map file, which defines all the information needed to provide help for an application. It works as follows: ◆ First, it sets $mapFile to the fully qualified pathname of the map file returned by the getMapFile() method. ◆ If the map file does not exist, the method returns FALSE. Chapter 12: Online Help System 413 15 549669 ch12.qxd 4/4/03 9:26 AM Page 413 ◆ The method then uses the built-in require_once() function to load the map file, which is a PHP script. ◆ If the $HELP_DIR variable in the map file has a value that does not start with leading slash character, the $HELP_DIR is a relative path and ROOT_PATH from help.conf is added as a prefix to this path; finally, it is stored in the object’s _HELP_DIR variable. Similarly, _REL_HELP_DIR is constructed using REL_ROOT_PATH (from help.conf) and the current application’s name. On the other hand, if the $HEL_DIR value does start with a leading slash, it is stored as is along with $REL_HELP_DIR in _HELP_DIR and the _REL_HELP_DIR object variables, respectively. ◆ The other variables in the map file — $REL_TEMPLATE_DIR, $DEFAULT_ SECTION_TEMPLATE , $TOC_TEMPLATE, $SEARCH_RESULT_TEMPLATE, $TEMPLATES, and $SECTIONS — are assigned to _REL_TEMPLATE_DIR, _DEFAULT_SECTION_TEMPLATE, _TOC_TEMPLATE, _SEARCH_RESULT_ TEMPLATE , _TEMPLATES, and _SECTIONS, respectively. getMapFile() This method returns the fully qualified pathname of the map file. readKeywordCacheFile() This method returns the named keyword file ($file), unserializes the contents, and returns the hash object. writeKeywordCacheFile() This methods writes the given word list, $words, in the named keyword file, $file. It first creates a hash called $cache using each of the keywords in the $words list and serializes the $cache object before writing to the file. writeSearchHistory() This method writes the keyword history hash ($hash) into the keyword search history file returned by the getFQPNSearchHistoryFile() method. The $hash is serialized before writing to the file. getKeywordFile() This method returns the fully qualified keyword index cache file name for the given section. _removeExcludedWords() This method removes words from the $words list if they are found in the EXCLUDED_WORD_FILE file. _getWords() This method reads the named file ($file), parses out text from HTML tags, creates a list of unique words, and returns the list. 414 Part II: Developing Intranet Solutions 15 549669 ch12.qxd 4/4/03 9:26 AM Page 414 _getUniqueWords() This method removes duplicates from the given word list ($words) and returns the duplicate-free word list. _loadFile() This method loads the given file ($file) if it exists and returns the contents as a string. HTMLtoText() This method removes HTML tags from the given string ($contents) and returns the HTML tag–free contents. Creating Application Configuration Files Like all other applications you’ve developed in this book, the online help applica- tions also use a standard set of configuration, message, and error files. These files are discussed in the following sections. Creating a main configuration file The primary configuration file for the entire system is called help.conf. Table 12-1 discusses each configuration variables. TABLE 12-1 THE help.conf VARIABLES NEED TO BE CHANGED 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. By default, this is set to the %DocumentRoot%/pear. $PHPLIB_DIR Set to the PHPLIB directory, which contains the PHPLIB packages; specifically the template.inc package needed for template manipulation. By default this is set to the %DocumentRoot%/phplib. $APP_FRAMEWORK_DIR Set to our application framework directory. By default this is set to the %DocumentRoot%/framework. Continued Chapter 12: Online Help System 415 15 549669 ch12.qxd 4/4/03 9:26 AM Page 415 . needed for class.DBI .php in our application framework. By default, this is set to the %DocumentRoot%/pear. $PHPLIB_DIR Set to the PHPLIB directory, which contains the PHPLIB packages; specifically. 413 ◆ The method then uses the built-in require_once() function to load the map file, which is a PHP script. ◆ If the $HELP_DIR variable in the map file has a value that does not start with leading. template.inc package needed for template manipulation. By default this is set to the %DocumentRoot%/phplib. $APP_FRAMEWORK_DIR Set to our application framework directory. By default this is set to

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