tailieunhanh - PHP and MySQL Web Development - P79

PHP and MySQL Web Development - P79: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | 362 Chapter 17 Using Network and Protocol Functions Listing directory HTML for the Submission Form head title Submit your site title head body h1 Submit site h1 form method post action URL input type text name url size 30 value http br Email contact input type text name email size 23 br input type submit name Submit site form body html This is a very simple form the rendered version with some sample data entered is shown in Figure . Figure Directory submissions typically require your URL and some contact details so directory administrators can notify you when your site is added to the directory. When the submit button is pressed we want to check first that the URL is hosted on a real machine and second that the host part of the email address is also on a real machine. We have written a script to check these things and the output is shown in Figure . 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 . Using Network Lookup Functions 363 Figure This version of the script displays the results of checking the hostnames for the URL and email address a production version might not display these results but it is interesting to see the information returned from our checks. Listing directory Script to Verify URL and Email Address html head title Site submission results title head body h1 Site submission results h1 php Extract form fields url HTTP_POST_VARS url email HTTP_POST_VARS email 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 364 Chapter 17 Using Network and Protocol Functions Listing Continued emailhost email 1 note that the getmxrr function is not implemented in Windows versions of PHP if getmxrr emailhost mxhostsarr echo Email address is .

TỪ KHÓA LIÊN QUAN