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

Secure PHP Development- P158 pot

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

Now suppose we want to create another application that deals with PocketPCs. Because PocketPCs are really PDAs with specific operating system (Windows CE) requirements, we can easily inherit the PDA class and define a new class called PocketPC as follows: <?php require_once ‘class.PDA.php’; class PocketPC extends PDA { function printSpec($type = null) { echo “CPU : “ . $this->getCPU() . “<br>”; echo “RAM : “ . $this->getRAM() . “<br>”; echo “TYPE : “ . $this->getType() . “<br>”; echo “Windows CE Only System <br>”; } } ?> In the preceding example, we have extended PDA and overridden the printSpec() method, as we want to print the fact that PocketPCs only run the Windows CE operating system. Therefore, an application such as the following can use this class: <?php require_once ‘class.PocketPC.php’; $info[‘CPU’] = ‘StrongArm 400 Mhz’; $info[‘RAM’] = ‘512 GB’; $info[‘TYPE’] = ‘PDA’; $myGizmo = new PocketPC($info); $myGizmo->printSpec(); ?> Appendix B: PHP Primer 761 32 549669 AppB.qxd 4/4/03 9:28 AM Page 761 This will output the following: CPU : StrongArm 400 Mhz RAM : 512 GB TYPE : PDA Windows CE Only System The classes discussed so far clearly show the power of OOP. Notice how we over- ride the PDA’s printSpec() method in the PocketPC class, but retain all the other benefits of the PDA, which happens to be a Computer object. 762 Part VII: Appendixes 32 549669 AppB.qxd 4/4/03 9:28 AM Page 762 Appendix C MySQL Primer MYSQL IS THE MOST POPULAR open-source database in the world. Its popularity stems from the following: ◆ MySQL is free as long as you don’t sell it to someone, sell a product that is bundled with it, or install and maintain it at a client site. If you’re in doubt about whether you fit within the license parameters, please see the Web site at http://www.mysql.com/. ◆ MySQL supports many programming interfaces, including PHP, C, C++, Java, Perl, and Python. The possibilities it offers to tailor programs to fit your needs are virtually limitless. ◆ MySQL uses very fast methods of relating tables of information to one another. Using a method called a one-sweep multijoin, MySQL is very effi- cient at gathering the information you request from many different tables at once. ◆ MySQL is widely used. Chances are good that many other people have done something similar to what you are doing. If you have questions or problems, you have a wide group of people to consult. Not only can you get advice from others about what to do, you can also get valuable infor- mation about what not to do. This prevents you from making the same mistakes others have made. MySQL is available all over the Internet. The best way to get MySQL is to go to http://www.mysql.com/ and find a mirror site close to you. You can find out how to install MySQL on a Linux platform in Appendix D. 763 33 549669 AppC.qxd 4/4/03 9:28 AM Page 763 Using MySQL from the Command-Line You can start the MySQL client program by typing the following: mysql -u username -p In this example, username is the username you are using to access the SQL server. If a password is required, you are prompted for it. You should now see some- thing like the following: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 143 to server version: 3.23.52 Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer. mysql> Creating a database When you install MySQL, you have no data. In fact, you don’t even have a database defined, other than the ones provided by MySQL itself. In this section, we will cre- ate a database called store. The syntax for this, at the mysql> prompt is simply create database store; You should get a response similar to the following: Query OK, 1 row affected (0.02 sec) This generic response indicates that your command has executed. You can con- firm this by issuing the following command: show databases; Your rights to create, change, or delete databases depends on your account and the rights associated with it. If you have root access you can (of course) do just about anything, including set parameters for other accounts. This chapter assumes that you have enough access to create and change data- bases. If you do have root access to MySQL, be sure to set/change the root password after installing MySQL! 764 Part VII: Appendixes 33 549669 AppC.qxd 4/4/03 9:28 AM Page 764 If this is the first database you create, you see the following: + + | Database | + + | mysql | | test | | store | + + 1 row in set (0.00 sec) Make sure you terminate each SQL query with a semicolon. Without a semi- colon terminator, you will see another prompt line and your query will not be executed. There it is. You now have a database named store that contains no data. Now it is up to you to create the tables that store the data. You need to define not only the names of all the columns, but also the types of data they store. Begin by identify- ing the database you’re going to use by issuing the following command: Use store; Then issue the following command to make the first table: create table customers ( id INT AUTO_INCREMENT PRIMARY KEY, name CHAR(40) NOT NULL, address CHAR(80), telephone CHAR(13)); Let’s examine each of these lines to see what it does, beginning with the first: id INT AUTO_INCREMENT PRIMARY KEY, This line is the meat of the table. In it, you are creating a column named id that holds whole numbers (int stands for integer). Additionally, this column is the pri- mary key. A primary key provides a convenient element to access the data in an orderly fashion. For example, in our database the records will be stored with unique integers as their primary key. Later, to access a record you could use a query to specify what record(s) to return by using that key. Searching for matches with a pri- mary key is significantly faster than other fields. Appendix C: MySQL Primer 765 33 549669 AppC.qxd 4/4/03 9:28 AM Page 765 . easily inherit the PDA class and define a new class called PocketPC as follows: < ?php require_once ‘class.PDA .php ; class PocketPC extends PDA { function printSpec($type = null) { echo “CPU :. system. Therefore, an application such as the following can use this class: < ?php require_once ‘class.PocketPC .php ; $info[‘CPU’] = ‘StrongArm 400 Mhz’; $info[‘RAM’] = ‘512 GB’; $info[‘TYPE’]. GB’; $info[‘TYPE’] = ‘PDA’; $myGizmo = new PocketPC($info); $myGizmo->printSpec(); ?> Appendix B: PHP Primer 761 32 549669 AppB.qxd 4/4/03 9:28 AM Page 761 This will output the following: CPU :

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