Use xmlhttp to add a domain name query function for a website

Source: Internet
Author: User
Tags domain name registration
When we are preparing to create a Web site, we must apply for an Internet domain name from the domain name registration authority. Therefore, we usually want to know whether the domain name we are preparing to use has been registered, you can visit the NIC site www.nic.net, click the & quot; whois & quot; link, and enter the domain name to be queried to get the results we need. When we are preparing to create a Web site, we must apply for an Internet domain name from the domain name registration authority. Therefore, we usually want to know whether the domain name we are preparing to use has been registered, you can access the NIC site http://www.nic.net, click the "whois" link and enter the domain name to query, you can get the results we need.

The WHOIS server is. com ,. net and. the query of the international top-level domain name in org returns all whois data, including the domain name registrant, management contract, and contact information (phone number, email, and address), Bill contact, technical support, and domain name server information are helpful for users to understand the basic information of a website. Many domain name registration service providers generally have whois (domain name query) advanced services, but personal websites do not have the qualifications and data of domain name registration service providers, therefore, the whois service cannot be provided under normal conditions.

In fact, with the xmlHTTP protocol, each of us can provide the domain name detail query (WHOIS) service on our personal website. This article describes how to use asp to implement this function with xmlhttp programming.

I. principle:

The principle is very simple. domain name query is mainly based on the WHOIS protocol provided by RFC 954. In the implementation process, we access the WHOIS database server of the NIC site through our own WEB server, query the content we need from the WHOIS database, and then combine it into a webpage through ASP and send it back to the client.

At the same time, we use xmlHttp protocol to achieve the refreshing effect of client Web pages and to request WHOIS data retrieval from the server.

The specific process is: the client requests domain name query through xmlhttp --> The ASP listening page on the WEB server receives the request and uses xmlhttp to send the retrieval command to the WHOIS server --> the WHOIS database performs the query operation, return results to our WEB server (in html format) --> after the WEB server receives the content, it immediately sends the result to the client-> the client browser uses vbscript to filter out the HTML excess, select the whois data to display.

II. Brief introduction to ASP XmlHttp programming:

1. client html page:

<Script language = "vbscript"> Sub submitemailonmouseup 'is triggered when you click the "query" button. Dim objXML, objXSL, objfso, strFile, strFileName, strXSL, strURL, theForm Set TheForm = Document. wordfind window. status = "retrieving data..." strURL = "dns. asp "Set objXML = CreateObject (" Microsoft. XMLHTTP ") 'create the XMLHTTP component of MS; stra =" submit = submit & fqdn = "& TheForm. words. value objXML. open "post", strURL, false' adopts the Post submission method; objXML. setrequestheader "conten T-length ", len (stra) objXML. setrequestheader "content-type", "application/x-www-form-urlencoded" objXML. send stra 'send message xmlGet = objXML. responseText: Wait a moment and get the result from the server. if instr (1, xmlGet, "This is not a valid. com. net. org. info or. biz domain name ", 1) <1 and len (trim (xmlGet)> 100 then if instr (1, xmlGet," This domain is available ", 1) <1 then if instr (1, xmlGet, "Registrant:", 1) then strFind1 = instr (1, x MlGet, "Registrant:", 1) else strFind1 = instr (1, xmlGet, "<PRe> <FONT face =" "Verdana, Arial", 1) + 65 strFind2 = instr (1, xmlGet, "</FONT> </pre>", 1) strFind4 = strFind2-strFind1 sHTML = mid (xmlGet, strFind1, strFind4) TheForm. comments. value = "query result:" + chr (13) + chr (10) + sHTML window. status = "query result: This domain name is already in use" else TheForm. comments. value = "Congratulations, this domain name is available! "Window. status =" query result: This domain name is still available! "End if else TheForm. comments. value =" invalid international top-level domain name! Enter an international domain name ending with (. com. net. org. info or. biz), for example, sun.com "window. status =" invalid international top-level domain name! Enter (. com. net. org. info or. biz, for example, CCTV.com "end if Set objXML = Nothing end sub </script> 

2. server-side ASP program:

<% Dim xmlGet, objXML, objXSL, objFSO, strFile, strFileName, strXSL, strURL xmlGet = "" if len (trim (Request. form ("fqdn")> 1 then strURL = "http://www.domainbank.net/whoisresults_gen.cfm? Show = 1 "'whois server address Set objXML = CreateObject (" Microsoft. XMLHTTP ") 'create the XMLHTTP component of MS stra =" submit = submit & fqdn = "& trim (Request. form ("fqdn") objXML. open "post", strURL, false objXML. setrequestheader "content-length", len (stra) objXML. setrequestheader "content-type", "application/x-www-form-urlencoded" objXML. send stra 'send information to the WhoIs database server; xmlGet = objXML. responseText 'get the information returned by the domain name server Set objXML = Nothing end if response. write xmlGet 'returns the result to the client. %>

In the above process, we can find that the ASP program in our WEB server actually serves only one intermediate transmission function. in actual application, this intermediate layer can also be omitted, vbscript is used to send and receive data directly to the WHOIS database through xmlhttp. However, in IE, "access data resources through (other) domains" may be disabled (default), resulting in insufficient permissions and execution failure, therefore, the method for removing the ASP intermediate layer in this province is not very common.

This program runs on IIS5.0 and IE6.0 based on Windows2000 platform. In actual use, you can copy the above code to your webpage and edit it on a simple page, you can add the domain name query function in the case that the page is not refreshed on your webpage. it looks like the service provided by the website of a professional domain name registration service provider.

The above describes how to use xmlhttp to add the domain name query function for the website. For more information, see PHP Chinese website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.