Specifications
The script that performs these checks uses two functions from the PHP network functions
suite—gethostbyname() and getmxrr(). The full script is shown in Listing 17.3.
LISTING 17.3 directory_submit.php—Script to Verify URL and Email Address
<html>
<head>
<title>Site submission results</title>
</head>
<body>
<h1>Site submission results</h1>
<?
// Check the URL
$url = parse_url($url);
$host = $url[host];
if(!($ip = gethostbyname($host)))
{
echo “Host for URL does not have valid IP”;
exit;
}
echo “Host is at IP $ip <br>”;
// Check the email address
$email = explode(“@”, $email);
$emailhost = $email[1];
if (!getmxrr($emailhost, $mxhostsarr))
{
echo “Email address is not at valid host”;
exit;
}
echo “Email is delivered via: “;
foreach ($mxhostsarr as $mx)
echo “$mx “;
// If reached here, all ok
echo “<br>All submitted details are ok.<br>”;
echo “Thank you for submitting your site.<br>”
.”It will be visited by one of our staff members soon.”
// In real case, add to db of waiting sites...
Advanced PHP Techniques
P
ART IV
376
22 7842 CH17 3/6/01 3:39 PM Page 376










