Page 544 - Beginning PHP 5.3
P. 544
Part III: Using PHP in Practice
❑ Server and script information: You discovered that, by reading values from the $_SERVER
superglobal array, you can retrieve useful information about the Web server and current script,
such as the visitor ’ s IP address, HTTP headers sent by the browser, and the location of the script
❑ Sending email messages: You learned how to send email using PHP ’ s mail() function, as well
as how to compose both plain text and HTML email messages. You saw how to add custom
headers to a message, and how to pass additional command - line arguments to the mail transfer
agent. You then used this knowledge to build a simple “ contact us ” form that allows visitors to
send email messages to the site owner
You now have the ability to write PHP scripts that do much more than simply send HTML pages to a
Web browser. In the next chapter you continue with this theme, and create PHP scripts that can generate
and display images on the fly. Meanwhile, try working through the following two exercises to test your
knowledge of PHP ’ s date handling and email sending functions. You can find the solutions to these
exercises in Appendix A.
Exercises
1. Write a PHP function that accepts a four - digit year and a month number (1 – 12), and returns the
number of weekdays (Monday – Friday) in the given month. Use this function to calculate the
number of weekdays in March 1997 and display the result.
2. Modify the contact.php contact form script in this chapter to allow a visitor to send an email
to anyone, not just the site owner. Include additional functionality to allow the visitor to copy
the email to an optional carbon copy (CC) recipient. (Incidentally, such a script is easily
exploitable by spammers, and therefore shouldn ’ t be placed on a publicly accessible Web site.)
506
9/21/09 9:15:42 AM
c16.indd 506 9/21/09 9:15:42 AM
c16.indd 506