Phát triển web với PHP và MySQL - p 41

Using Network and Protocol Functions CHAPTER 17 375 LISTING Continued URL: Email contact: This is a very simple form—the rendered version, with some sample data entered, is shown in Figure . 17 USING NETWORK AND PROTOCOL FUNCTIONS 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. | Using Network and Protocol Functions 375 Chapter 17 Listing Continued 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 . 17 Using Network and Protocol Functions 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 . 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. 376 Advanced PHP Techniques Part IV 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 . Listing directory 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. .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.