Specifications
If the URL is valid, we then go on to check the email address. First, we split it into username
and hostname with a call to explode():
$email = explode(“@”, $email);
$emailhost = $email[1];
When we have the host part of the address, we can check to see if there is a place for that mail
to go using the getmxrr() function:
getmxrr($emailhost, $mxhostsarr)
This function returns the set of MX (Mail Exchange) records for an address in the array you
supply at $mxhostarr.
An MX record is stored at the DNS and is looked up like a hostname. The machine listed in
the MX record isn’t necessarily the machine where the email will eventually end up. Instead
it’s a machine that knows where to route that email. (There can be more than one, hence this
function returns an array rather than a hostname string.) If we don’t have an MX record in the
DNS, then there’s nowhere for the mail to go.
If all these checks are okay, we can put this form data in a database for later review by a staff
member.
In addition to the functions we’ve just used, you can use the more generic function
checkdnsrr(), which takes a hostname and returns true if there is any record of it in
the DNS.
Using FTP
File Transfer Protocol, or FTP, is used to transfer files between hosts on a network. Using PHP,
you can use fopen() and the various file functions with FTP as you can with HTTP connec-
tions, to connect to and transfer files to and from an FTP server. However, there is also a set of
FTP-specific functions that comes with the standard PHP install.
These functions are not built in to the standard install by default. In order to use them under
UNIX, you will need to run the PHP configure program with the --enable-ftp option, and
then rerun make. To use the FTP functions with the Win32 binary, you will need to add the line
extension=php_ftp.dll
under the “Windows Extensions” section of your php.ini file. (For more details on configur-
ing PHP, see Appendix A, “Installing PHP 4 and MySQL.”)
Advanced PHP Techniques
P
ART IV
378
22 7842 CH17 3/6/01 3:39 PM Page 378










