13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

456 Chapter 20 Using Network <strong>and</strong> Protocol Functions<br />

This is a simple form; the rendered version, with some sample data entered, is shown in<br />

Figure 20.2.<br />

Figure 20.2 Directory submissions typically require your URL <strong>and</strong> some<br />

contact details so directory administrators can notify you when<br />

your site is added to the directory.<br />

When the submit button is clicked, you want to first check that the URL is hosted on a<br />

real machine, <strong>and</strong>, second, that the host part of the email address is also on a real<br />

machine.We wrote a script to check these things, <strong>and</strong> the output is shown in Figure<br />

20.3.<br />

Figure 20.3 This version of the script displays the results of checking the<br />

hostnames for the URL <strong>and</strong> email address; a production version might<br />

not display these results, but it is interesting to see the information<br />

returned from the checks.<br />

The script that performs these checks uses two functions from the <strong>PHP</strong> network functions<br />

suite: gethostbyname() <strong>and</strong> dns_get_mx().The full script is shown in Listing 20.3.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!