Secure PHP Building 50 Practical Applications Development phần 7 docx

92 146 0
Secure PHP Building 50 Practical Applications Development phần 7 docx

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

setEcampaignCampaignID() This method sets the current campaign ID to the campaign ID parameter if it is not null and returns the current campaign ID. getURLResponse() This method returns URL click-through count for each tracked URL in a campaign. getUnsubResponse() This method returns the total unsubscription track for a campaign. getBounceResponse() This method returns the total number of immediate bounces for a given campaign. Creating Common Configuration and Resource Files Like all other applications you’ve developed in this book, the e-campaign applica- tions also use a standard set of configuration, message, and error files. These files are discussed in the following sections. Creating an e-campaign configuration file The primary configuration file for the entire e-campaign system is called ecampaign.conf, which can be found in ch15/apps directory in the CDROM. Table 15-2 discusses each configuration variable. TABLE 15-2 ecampaign.conf VARIABLES Configuration Variable Purpose $PEAR_DIR Set to the directory containing the PEAR package; specifically the DB module needed for class.DBI.php in the application framework. $PHPLIB_DIR Set to the PHPLIB directory, which contains the PHPLIB packages; specifically the template.inc package needed for template manipulation. $APP_FRAMEWORK_DIR Set to the application framework directory. Continued Chapter 15: E-campaign System 523 19 549669 ch15.qxd 4/4/03 9:26 AM Page 523 TABLE 15-2 ecampaign.conf VARIABLES (Continued) Configuration Variable Purpose $PATH Set to the combined directory path consisting of the $PEAR_DIR, the $PHPLIB_DIR, and the $APP_FRAMEWORK_DIR. This path is used with the ini_set() method to redefine the php.ini entry for include_path to include $PATH ahead of the default path. This allows PHP to find the application framework, PHPLIB, and PEAR-related files. $AUTHENTICATION_URL Set to the central login application URL. $LOGOUT_URL Set to the central logout application URL. $HOME_URL Set to the topmost URL of the site. If the URL redirection application does not find a valid URL in the e-campaign database to redirect to for a valid request, it uses this URL as a default. $APPLICATION_NAME Internal name of the application. $XMAILER_ID This is the X-Mailer mail header sent with each mail to identify what program was used to send mail. $DEFAULT_LANGUAGE Set to the default (two- digit) language code. $ROOT_PATH Set to the default (two-digit) language code. $REL_ROOT_PATH Relative path to the root directory. $REL_APP_PATH Relative application path as seen from the Web browser. $ECAMPAIGN_MENU_URL Relative URL path to the campaign manager interface application. $TEMPLATE_DIR Set to the template directory containing the ihtml template files needed for the user-management applications. $CLASS_DIR Set to the class directory where user-management- related class files are stored. $ECAMPAIGN_LIST_CLASS Name of the List class. $ECAMPAIGN_URL_CLASS Name of the URL class. 524 Part III: Developing E-mail Solutions 19 549669 ch15.qxd 4/4/03 9:26 AM Page 524 Configuration Variable Purpose $ECAMPAIGN_TRACK_CLASS Name of the URL Track class. $ECAMPAIGN_UNSUB_CLASS Name of the Unsubscription class. $ECAMPAIGN_CAMPAIGN_CLASS Name of the Campaign class. $ECAMPAIGN_MESSAGE_CLASS Name of the Message class. $ECAMPAIGN_REPORT_CLASS Name of the Report class. $ECAMPAIGN_MNGR Name of the campaign manager interface application. This application displays the primary user interface. $ECAMPAIGN_URL_MNGR Name of the URL manager application. $ECAMPAIGN_CAMPAIGN_MNGR Name of the campaign manager application. $ECAMPAIGN_LIST_MNGR Name of the list manager application. $ECAMPAIGN_MESSAGE_MNGR Name of the message manager application. $ECAMPAIGN_EXEC_MNGR Name of the campaign execution application. $ECAMPAIGN_REPORT_MNGR Name of the report manager application. $ECAMPAIGN_REDIR_MNGR Name of the URL redirection application. $ECAMPAIGN_UNSUB_MNGR Name of the unsubscription application. $REL_TEMPLATE_DIR Set to relative template directory. $ECAMPAIGN_DB_URL Set to campaign database URL. $MAX_DELIVERY_AT_A_TIME Set to maximum e-mail delivery count per run. Because the execution application cannot run the entire campaign in one shot due to browser timeout issues, it executes this number of e-mails at a time. The execution application calls itself after each run using the meta refresh method. $MAX_WAIT_PER_DELIVERY The number of seconds the campaign execution application waits before it restarts via the meta refresh tag. $SECRET A random number used in the checksum algorithm. $ECAMPAIGN_LIST_TBL Name of the list table. $ECAMPAIGN_URL_TBL Name of the URL table. Continued Chapter 15: E-campaign System 525 19 549669 ch15.qxd 4/4/03 9:26 AM Page 525 TABLE 15-2 ecampaign.conf VARIABLES (Continued) $LIST_FIELD_MAP_TBL Name of the list map table. $ECAMPAIGN_TBL Name of the campaign table. $ECAMPAIGN_MESSAGE_TBL Name of the message table. $MESSAGE_HDRS_TBL Name of the message header table. $ECAMPAIGN_EXECUTION_TBL Name of the execution table. $ECAMPAIGN_ASSEMBLY_TBL Name of the assembly table. $ECAMPAIGN_TRACK_TBL Name of the URL track table. $ECAMPAIGN_UNSUB_TBL Name of the unsubscription table. $ECAMPAIGN_BOUNCED_TBL Name of the bounced e-mail table. $REPORT_EVEN_ROW_COLOR HTML color code for even rows in a report table. $REPORT_ODD_ROW_COLOR HTML color code for odd rows in a report table. $FROM_HEADER Header ID for the From header. $REPLY_HEADER Header ID for the Reply-to header. $PRIORITY_HEADER Header ID for the Priority header. $SUBJECT_HEADER Header ID for the Subject header. Creating an e-campaign messages file The messages displayed by the e-campaign applications are stored in an e-campaign messages file called ecampaign.messages, which can be found in ch15/apps directory in the CDROM. Creating an e-campaign errors file The error messages displayed by the e-campaign applications are stored in an e-campaign error messages file called ecampaign.errors, which can be found in ch15/apps directory in the CDROM. Creating Interface Template Files The HTML interface templates needed for the e-campaign applications are included on the CD-ROM. These templates contain various template tags to dynamically 526 Part III: Developing E-mail Solutions 19 549669 ch15.qxd 4/4/03 9:26 AM Page 526 display necessary information. Table 15-3 shows which template file is used for what purpose. TABLE 15-3 INTERFACE TEMPLATE FILES Configuration Variable File Name and Purpose $ECAMPAIGN_ADD_TEMPLATE ecampaign_add.ihtml $ECAMPAIGN_MENU_TEMPLATE ecampaign_menu.ihtml $ECAMPAIGN_ADD_URL_TEMPLATE ecampaign_add_url.ihtml $ECAMPAIGN_EXECUTION_TEMPLATE ecampaign_execute.ihtml $ECAMPAIGN_ADD_LIST_TEMPLATE ecampaign_add_list.ihtml $STATUS_TEMPLATE ecampaign_status.ihtml $ECAMPAIGN_MAPPING_TEMPLATE ecampaign_take_map.ihtml $ECAMPAIGN_ADD_CAMPAIGN_TEMPLATE ecampaign_add_campaign.ihtml $ECAMPAIGN_ADD_LABEL_TEMPLATE ecampaign_add_label.ihtml $ECAMPAIGN_REPORT_TEMPLATE ecampaign_report.ihtml $ECAMPAIGN_MOD_URL_TEMPLATE ecampaign_modify_url.ihtml $ECAMPAIGN_ADD_MESSAGE_TEMPLATE ecampaign_add_message.ihtml $ECAMPAIGN_PREVIEW_MESSAGE_TEMPLATE ecampaign_preview_message $ECAMPAIGN_MOD_LIST_TEMPLATE ecampaign_mod_list.ihtml $ECAMPAIGN_UNSUB_TEMPLATE ecampaign_unsub.ihtml $MAIL_TEMPLATE ecampaign_mail.ihtml $ECAMPAIGN_PREVIEW_MESSAGE_ ecampaign_preview_message_ INPUT_TEMPLATE input.ihtml $ECAMPAIGN_PREVIEW_MESSAGE_ ecampaign_preview_message_ SHOW_TEMPLATE show.ihtml $ECAMPAIGN_PREVIEW_MESSAGE_TEMPLATE ecampaign_preview_ message.ihtml $ECAMPAIGN_UNSUB_CONFIRM_TEMPLATE ecampaign_unsub_ confirmation.ihtml Now you’re ready to create the e-campaign applications. Chapter 15: E-campaign System 527 19 549669 ch15.qxd 4/4/03 9:26 AM Page 527 Creating an E-campaign User Interface Application This application displays the main user interface for the e-campaign applications. The main user interface application called ecampaign_mngr.php can be found in ch15/apps directory in the CDROM. The methods implemented by this user inter- face application are discussed in the following sections. run() This method calls the displayMenu() method to display the user interface. displayMenu() This method displays the main user interface. This method creates a List object, a URL object, and a Campaign object to get lists of lists, URLs, and campaigns to dis- play in the interface. authorize() This method returns TRUE since, in the current version everyone is allowed to view the campaign report. If you want to restrict access to the report to a specific user or group of users, you’ll have to modify this method to implement your restrictions. Creating a List Manager Application The list-management application manipulates lists. The list-creation process is shown in Figure 15-3. The ecampaign_list_mngr.php application that can be found in ch15/apps directory in the CDROM, which implements the list creation, modification, and deletion process. This application has the following methods. run() This method uses a form variable called the $cmd variable, which is set in the user interface displayed by ecampaign_mngr.php, to select the appropriate function to implement the list operation. When $cmd is set to add, it calls the addDriver() method to add a list. When $cmd is set to modify, it calls the modDriver() method to modify a list; otherwise, it calls the delList() method to delete a list. 528 Part III: Developing E-mail Solutions 19 549669 ch15.qxd 4/4/03 9:26 AM Page 528 Figure 15-3: How a list is created. addDriver() This method uses $step, a variable set in the add list interface forms, to control which method is called. The $step variable is used to select the appropriate method for the appropriate stage of the list adding process. Here is how the addDriver() works: ◆ If $step is not set, then the first step of the add list process is started by calling displayAddListMenu(), which shows the add list interface. This interface sets the $step to 2, using a hidden HTML field. ◆ If $step is set to 2, then the second step of the add list process is started by calling the addList() method. This method stores the list configura- tion data collected in the previous step and displays the database field mapping interface by calling the takeMap() method. This interface sets the $step value to 3. Start Get list configuration information such as database hostname, database name, username, password, and the table name, which contains the customer data (EMAIL, RECORD ID, etc.) Ask user to give this list a name. End Connect to the given list database and get meta data for the chosen list table. Map table fields with standard campaign fields (used for personalization) Store list access and mapping information in e-campaign database Chapter 15: E-campaign System 529 19 549669 ch15.qxd 4/4/03 9:26 AM Page 529 ◆ If $step is set to 3, then the database field map that maps the standard personalization fields such as REC_ID, FIRST, LAST, AGE, SEX, INCOME, and EMAIL is stored in the database using the addDatabaseFieldMap method. modifyDriver() This method uses $step, a variable set in the modify list interface forms, to control which method is called. The $step variable is used to select the appropriate method for the appropriate stage of the list modification process. Here is how the modifyDriver() method works: ◆ If $step is not set, then the first step of the modify list process is started by calling displayModifyListMenu(), which shows the modify list inter- face. This interface sets the $step to 2, using a hidden HTML field. ◆ If $step is set to 2, then the second step of the modify list process is started by calling the modifyList() method. This method stores the list configuration data collected in the previous step and displays the database field mapping interface by calling the takeMap() method. This interface sets the $step value to 3. ◆ If $step is set to 3, then the database field map that maps the standard personalization fields such as REC_ID, FIRST, LAST, AGE, SEX, INCOME, and EMAIL are stored in the database using the modifyDatabaseFieldMap method. authorize() See the authorize() method in the e-campaign user interface application called ecampaign_mngr.php for details. displayAddListMenu() This method displays the add list interface. displayModListMenu() This method displays the modify list interface. modifyList() This method is called when a user makes changes in the modify interface shown by displayModListMenu(). The modifyList() method creates a list object and calls its modEcampaignList() method to update the list in the database. 530 Part III: Developing E-mail Solutions 19 549669 ch15.qxd 4/4/03 9:26 AM Page 530 If the database is successfully updated, the modifyList() method calls takeMap() to show the database and personalization field map interface. If the update fails, it shows an appropriate status message. modifyDatabaseFieldMap() This method uses a list object to call its modifyMapList() method to update the map data in the database. The map interface is displayed by the takeMap() method. delList() This method uses a list object to call its deleteList() method to delete the list. It displays an appropriate status message based on the success or failure of the deleteList() method. takeMap() This method allows you to map the database fields to the standard personalization fields REC_ID, EMAIL, FIRST, LAST, AGE, INCOME, and SEX. It works as follows: ◆ It connects to the list database using a DBI object called $dbiObj. ◆ If the connection to the list database is successful, it performs a select query to detect if the list table exists in the list database. If the table does not exist, the list is deleted from the database. ◆ If the table exists, the takeMap() method uses the tableInfo() method on the query result object, $result, to get the list table’s meta data — field name and type. ◆ Then it shows an interface that allows the user to map each standard personalization field to a database field. The user must map at least REC_ID (record ID) and the EMAIL (email address). addList() This method is called when a user makes changes in the add interface shown by displayAddListMenu(). It works as follows: ◆ First, it checks to see if the user supplied all the required fields: list name ($listname), database host name ($db_host), database user name ($db_user), database type ($db_type), database table name ($db_table). If these fields are empty, then an alert message is shown and the user is returned to the previous screen. ◆ If the required fields are supplied, a list object called $ecampaignListObj is created and its addNewEcampaignList() is called to add the list in the database. Chapter 15: E-campaign System 531 19 549669 ch15.qxd 4/4/03 9:26 AM Page 531 ◆ If the list is successfully added, the takeMap() method is called to display the map interface. ◆ If the list is not added due to database failure, an appropriate failure message is displayed. addDatabaseFieldMap() This method adds database fields to standard personalization field mapping to the database using a list object’s addMapping() method. Creating a URL Manager Application The URL manager allows you to add, delete, and modify trackable URLs. Figure 15-4 shows how URLs are added to the database using a simple user interface, how it’s used in a message template using the {URLx} tag and replaced with a redirection URL in the message received by end-users, and how the redirection URL is finally resolved in the final target URL being tracked. The ecampaign_url_mngr.php, which can be found in ch15/apps directory in the CDROM implements the URL manager application using the methods discussed in the following sections. run() This method uses a form variable called $cmd variable, which is set in the user interface displayed by ecampaign_mngr.php, to select the appropriate function to implement the list operation. When $cmd is set to delete, it calls the delList() method to delete a URL. When $cmd is set to modify, it calls the modifyURL() method to modify a URL; otherwise, it calls the addURL() method to add a URL. addURLDriver() This method controls the add URL process using the interface variable $step. Here’s how it works: ◆ If $step is not set, then displayAddURLMenu() is called to display the add URL interface. This interface sets $step to 2, using a hidden HTML field. ◆ If $step is set to 2, then addURL() is called to add the URL in the database. authorize() See the authorize() method in the e-campaign user interface application called ecampaign_mngr.php for details. 532 Part III: Developing E-mail Solutions 19 549669 ch15.qxd 4/4/03 9:26 AM Page 532 [...]... System User interface Name EVOKNOW PHP Site URL http://www.evoknow.com /php URL_ID NAME URL 1 EVOKNOW PHP Site http://www.evoknow.com /php/ E-campaign Database EVOKNOW PHP Site Message Template Click here to visit our PHP site Source of Sent Message Click here to visit our PHP site URL Tracking & Redirection... assume that the e-campaign applications can be accessible via the http://www.evoknow.com /php/ ecampaign/ecampaign_mngr .php main interface application Creating a list To create the previously mentioned list, run the ecampaign_mngr .php application and click on the Add List button This will show the interface shown in Figure 15-11 549 19 549669 ch15.qxd 550 4/4/03 9:26 AM Page 550 Part III: Developing E-mail... database 19 549669 ch15.qxd 4/4/03 9:26 AM Page 539 Chapter 15: E-campaign System User Interface PHP Weekly Newsletter Campaign PHP User List PHP Newsletter Msg Database CAMPAIGN_ID 1 LIST_ID 1 MSG_ID 1 NAME PHP Weekly Newsletter Campaign Figure 15-6: How the campaign manager works The ecampaign_campaign_mngr .php which can be found in the ch15/apps directory in the CDROM, implements the campaign management... gender, etc Click here to buy PHP applications. Click here to learn more. To subscribe click here Dear {FRIST} Rendered Message The message contents can be personalized with other fields such as last name, email address, age, gender, etc Click here to buy PHP applications Click here to learn more To unsubscribe click... to be modified before you start using the redir .php and unsub .php applications in real-world email campaign scenarios At the least, you should change the value of $SECRET in the configuration file Because the current algorithms are published in the book, someone can easily guess how to defeat them For example, the computeCheckSum() method in the redir .php application can be changed to: function computeCheckSum()... server), the performance will very based on your mail server’s abilities 555 19 549669 ch15.qxd 4/4/03 9:26 AM Page 556 20 549669 PP04.qxd 4/4/03 9:26 AM Page 5 57 Part IV Using PHP for Sysadmin Tasks CHAPTER 16 Command-Line PHP Utilities CHAPTER 17 Apache Virtual Host Maker CHAPTER 18 BIND Domain Manager 20 549669 PP04.qxd 4/4/03 9:26 AM Page 558 ... user-interface application called ecampaign_mngr .php for details 19 549669 ch15.qxd 4/4/03 9:26 AM Page 549 Chapter 15: E-campaign System toggleDescField() This is a utility method that toggles the DESC option used in the report column title links to toggle the column’s ascending or descending order Testing the E-Campaign System Now that you have all the e-campaign applications built, you’re ready to test... table called PHPCustomers with fields called custid (REC_ID), fname (FIRST), lname (LNAME), and e-mail (EMAIL) I also assume that this database is on a host called diablo.evoknow.com and the user name and password needed to access this MySQL database are scott and tiger, respectively Also, make sure that you have some valid data in the table to be able to test the campaign If you have a PHP MyAdmin... performs a chunk-size number of delivery and then calls itself from the Web status screen using an HTTP meta refresh trick The entire execution process is shown in Figure 15 -7 The campaign execution application called ecampaign_execution .php, which can be found in ch15/apps directory in the CDROM, performs the e-mail delivery using the methods discussed in the following sections run() This method calls the... Show error message Click here to visit ROI Mail Thanks again! Kind Regards, PHP Team, EVOKNOW Yes Locate URL target and redirect user to the target URL E-campaign Database Click here to remove from future mailing Add track record in database End Figure 15-8: How the URL tracking and redirection application works The redir .php, which can be found in the ch15/apps directory in the CDROM, implements the . the database. Name EVOKNOW PHP Site URL URL_ID 1 NAME EVOKNOW PHP Site URL http://www.evoknow.com /php/ http://www.evoknow.com /php Click <a href="{URL1}">here</a> to visit our PHP site. Click. package; specifically the DB module needed for class.DBI .php in the application framework. $PHPLIB_DIR Set to the PHPLIB directory, which contains the PHPLIB packages; specifically the template.inc package. is called to add the campaign in the database. PHP Weekly Newsletter Campaign PHP User List PHP Newsletter Msg CAMPAIGN_ID 1 LIST_ID 1 MSG_ID 1 PHP Weekly Newsletter Campaign NAME User Interface Database Chapter

Ngày đăng: 13/08/2014, 12:21

Tài liệu cùng người dùng

Tài liệu liên quan