March 14th, 2008
560 Part IV: Using PHP for Sysadmin Tasks Working with the Command-Line Interpreter The command-line version of PHP is installed when you enable CGI support during the PHP installation process. The command-line PHP interpreter can be found by running the following: which php This will show the full path of the PHP command-line interpreter. Sample output appears as follows: /usr/bin/php In most cases, you should find the PHP binary in the /usr/bin directory, which is typically in your path, so you can run the following: php -h The 4.3.x version of the PHP command-line interpreter will display output similar to following: Usage: php [options] [-f] [args…] php [options] -r [args...] php [options] [-- args...] -s Display color syntax highlighted source. -w Display source with stripped comments and whitespace. -f Parse . -v Version number -c
| Look for php.ini file in this directory -a Run interactively -d foo[=bar] Define INI entry foo with value bar -e Generate extended information for debugger/profiler -z Load Zend extension . -l Syntax check only (lint) -m Show compiled in modules -i PHP information -r Run PHP without using script tags ..?> -h This help args… Arguments passed to script. Use — args when first argument starts with - or script is read from stdin
Posted in JSP | No Comments »
March 14th, 2008
Chapter 16 Command-Line PHP Utilities IN THIS CHAPTER . Writing command-line PHP utilities . How to create a cron-based reminder . How to develop a geographic location query tool for IP . Developing a spam-busting utility for POP3 mailboxes . How to develop a hard disk monitoring tool . Creating a CPU load monitoring tool PHP STARTED OUT AS A SIMPLE Web scripting tool written in Perl and later became the most popular Web application development language. Because of its strong ties with the Web, it has lagged behind as an all-purpose programming language. Especially for command-line users, PHP is considered a newcomer, because not many command-line PHP utilities are floating around on the Internet just yet. In this chapter, you develop a few command-line utilities to get you started in command-line PHP development. Most of the scripts discussed here might not work on a Windows platform. They have been tested on the Linux platform only.
Posted in JSP | No Comments »
March 13th, 2008
Part IV Using PHP for Sysadmin Tasks CHAPTER 16 Command-Line PHP Utilities CHAPTER 17 Apache Virtual Host Maker CHAPTER 18 BIND Domain Manager
Posted in JSP | No Comments »
March 13th, 2008
Chapter 15: E-campaign System 555 Security Considerations The checksum algorithm used in making trackable URL links and unsubscription URL needs 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() { global $SECRET; $u = $this->getRequestField( u ); $uid = $this->getRequestField( uid ); $c = $this->getRequestField( c ); return ($u << 4) + ($uid << 3) + ($c << 7) + $SECRET; } Here this version uses different bit shifts for $u, $uid, and $c. Of course you should choose your own values to make sure they are not known to anyone. The best approach would be to come up with a completely new algorithm that does not use even the same bit shifting technique. I will leave that to you to develop. Summary In this chapter you learned to develop a simple email campaign system that allows you to send personalized, URL tracked HTML messages to email addresses found in MySQL databases. Note that since the email campaign system uses your default mail transport agent (i.e. mail server), the performance will very based on your mail server s abilities.
Posted in JSP | No Comments »
March 12th, 2008
554 Part III: Developing E-mail Solutions Give a name to your campaign, select a list and a message, and save the campaign. That s all there is to creating a campaign! Now you re ready to execute this test campaign. Executing a campaign Select the campaign from the bottom of the main user interface shown by ecmapaign_mngr.php, and click on the red Execute button. The campaign will be executed and a status message will be shown as shown in Figure 15-16. Figure 15-16: Executing a campaign. Now access the campaign e-mail in your e-mail client program. Viewing a campaign report After you ve executed the campaign, the campaign report becomes available immediately. You can view the campaign report by selecting the campaign name from the main user interface shown by ecampaign_mngr.php and clicking on the Show Report button. If you view the report before any URL is clicked by any user, the report will show no URL track. If you click on a tracked URL in a message and then check the report, you ll see your track being reported. You can click on the URL in your message as many times as you want, and you ll notice that the report accurately reports the unique and total URL clicks. Figure 15-10 shows a sample report. Like URL clicks, the unsubscription tracks are also reported in the report.
Posted in JSP | No Comments »
March 12th, 2008
Chapter 15: E-campaign System 553 If you want to track URLs, you can insert one or more trackable URLs from the URL list. If you enter the URL directly in the message, it will not be tracked by the redirection application. Only URLs that are inserted from the URL list are tracked. When inserting URLs in the message, consider using labelinstead of inserting raw URL in the message. The automatically generated redirection URLs are not pretty to look at, so they re best kept somewhat invisible from the average user by using the HTML anchor link tag. After you ve created the message, you can preview it or save it. If you decided to preview it, you ll be asked to fill out the standard personalization field values once, because during preview no real list data from the database is fetched. Save the message after you have previewed. Remember that this e-campaign system only sends an HTML message, so you must use proper HTML tags to format your message so it s rendered properly in modern e-mail clients such as Outlook Express. Creating a campaign After you ve created a list, one or more URLs (if you want to add URLs in the message), and a message, you re ready to create a campaign. Click on the Add Campaign button in the main user interface shown by ecampaign_mngr.php to add a campaign from an interface similar to Figure 15-15. Figure 15-15: Creating a campaign.
Posted in JSP | No Comments »
March 11th, 2008
552 Part III: Developing E-mail Solutions Add a URL of your choice and give a name to the URL. Submit the URL and it should be stored in the database. Repeat this process as many times as you want, to create multiple URLs. These URLs will be trackable. Creating a message Next create a message by clicking on the Add Msg button. You ll see a screen like the one in Figure 15-14. Create a message to your liking by filling out the form. You can enter the same information as shown in the screen if you want. Figure 15-14: Creating a message. You can personalize the message, as shown in Figure 15-14, by selecting the personalization menu and inserting the appropriate tags. Due to JavaScript limitations, the personalization tag is always appended to the message at the end. You can simply copy and paste it in the designed location. The same is also true for URLs.
Posted in JSP | No Comments »
March 11th, 2008
Chapter 15: E-campaign System 551 Figure 15-12: Mapping database fields. Figure 15-13: Creating a URL.
Posted in JSP | No Comments »
March 11th, 2008
550 Part III: Developing E-mail Solutions Figure 15-11: Configuring a list. Enter the necessary information as assumed earlier and submit the information. If the ecampaign_list_mngr.php application is able to connect to the given database using the user name and password, it will retrieve the metadata for the given table and display a mapping interface, as shown in Figure 15-12. Map the fields as shown and save the list. After the list is created, you can modify or delete it as you please. Keep the list for the time being so that you can continue with the test. Creating a target URL Now create one or more URLs that you can use in your e-mail campaign. Click on the Add URL button from the main user interface shown by the ecampaign_mngr.php application. This will show a screen like the one in Figure 15-13.
Posted in JSP | No Comments »
March 9th, 2008
Chapter 15: E-campaign System 549 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 them. You ll need a database with a table that has numeric record ID (to be mapped to REC_ID), an e-mail address field (to be mapped to EMAIL), and, optionally, the first name field (to be mapped to FIRST) and last name field (to be mapped to LAST). Of course, you can have additional fields that map to AGE, SEX, INCOME, and so on, as well as standard personalization fields. In this test, I assume that you have a test database called PRODDB, which has a 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 application installed on a system, you can easily add sample data via its interface. We also 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.
Posted in JSP | No Comments »