Use PHP to query domain name status whois class _ PHP Tutorial

Source: Internet
Author: User
Use PHP to query the domain name status whois class. Copy the code as follows :? ClassSearchDomain {var $ domain; functionSetDomain ($ udomain) {$ this-domain $ udomain;} get whois and analyze the domain name status. OK is not registered. it is not empty. The code is as follows:


Class SearchDomain
{
Var $ domain = "";
Function SetDomain ($ udomain)
{
$ This-> domain = $ udomain;
}
//
// Obtain whois and analyze the domain name status
// OK is not registered
// Non-null expiration time
// Null value unknown
//
Function GetInfo ()
{
/*
$ Dinfo = trim ($ this-> GetWhois ());
If ($ dinfo = "") return "";
If (eregi ("no match", $ dinfo) return "OK ";
// Return $ rs;
*/
$ Wl = "";
$ W_server = $ this-> GetServer ();
If ($ w_server = "") return "";
$ Fp = fsockopen ($ w_server, 43, $ errno, $ errstr, 30 );
If (! $ Fp)
{
Echo $ errstr;
Return "";
}
$ Out = $ this-> domain. "\ r \ n ";
$ Out. = "Connection: Close \ r \ n ";
Fputs ($ fp, $ out );
While (! Feof ($ fp ))
{
$ Wl = fgets ($ fp, 255 );
If (eregi ("no match", $ wl ))
{
Fclose ($ fp );
Return "OK ";
}
If (eregi ("Expiration Date", $ wl ))
{
$ Lines = split (":", $ wl );
$ T = trim ($ lines [1]);
$ Ts = split ("", $ t );
$ T = $ ts [0];
If (ereg ("[^ 0-]", $ t ))
{
$ Ts = split ("-", $ t );
$ T = $ ts [2]. "-". $ this-> MonthToNum ($ ts [1]). "-". $ ts [0];
}
Fclose ($ fp );
Return $ t;
}
}
Fclose ($ fp );
Return "";
}
//
// Obtain the whole whois information of the domain name
//
Function GetWhois ()
{
$ Wh = "";
$ W_server = $ this-> GetServer ();
If ($ w_server = "") return "";
$ Fp = fsockopen ($ w_server, 43, $ errno, $ errstr, 30 );
If (! $ Fp)
{
Echo $ errstr;
Return "";
}
$ Out = $ this-> domain. "\ r \ n ";
$ Out. = "Connection: Close \ r \ n ";
Fputs ($ fp, $ out );
While (! Feof ($ fp ))
{
$ Wh. = nl2br (fgets ($ fp, 255 ));
}
Fclose ($ fp );
Return $ wh;
}
//
// Output the status information of the current domain name
//
Function PrintSta ()
{
$ Rs = $ this-> GetInfo ();
If ($ rs = "OK") echo $ this-> domain. "not registered!
\ R \ n ";
Else if ($ rs = "") echo "unable to query". $ this-> domain. "status!
\ R \ n ";
Else echo $ this-> domain. "registered, Expiration Time: $ rs
\ R \ n ";
}
//
// Obtain the whois query server
//
Function GetServer ()
{
$ Udomain = substr ($ this-> domain,-3 );
Switch ($ udomain)
{
Case "com ":
$ W_server = "whois.internic.net ";
Break;
Case "net ":
$ W_server = "whois.internic.net ";
Break;
Case "org ":
$ W_server = "whois.pir.org ";
Break;
Case "nfo ":
$ W_server = "whois.afilias.info ";
Break;
Case "biz ":
$ W_server = "whois. biz ";
Break;
Case ". cc ":
$ W_server = "whois. nic. cc ";
Break;
Case "edu ":
$ W_server = "whois.educause.net ";
Break;
Case "gov ":
$ W_server = "whois.nic.gov ";
Break;
Case ". cn ":
$ W_server = "whois.cnnic.net.cn ";
Break;
Default:
$ W_server = "";
}
Return $ w_server;
}
//
// Convert the month in English to a number.
//
Function MonthToNum ($ m)
{
$ M = strtolower ($ m );
For ($ I = 1; $ I <= 12; $ I ++)
{
$ Tt = mktime (2005, 0, $ I + );
If ($ m = strtolower (strftime ("% B", $ tt )))
{
If ($ I> 9) return $ I-1;
Else return "0". $ I-1;
}
}
}
}

$ Sd = new SearchDomain ();
$ Sd-> SetDomain ("job-sky.com ");

// Query whether the domain name is registered, equivalent to $ sd-> PrintSta ();
$ Rs = $ sd-> GetInfo ();
If ($ rs = "OK") echo $ sd-> domain. "not registered!
\ R \ n ";
Else if ($ rs = "") echo "unable to query". $ sd-> domain. "status!
\ R \ n ";
Else echo $ sd-> domain. "registered, Expiration Time: $ rs
\ R \ n ";

// Obtain the detailed whois information of the domain name
// Echo $ sd-> GetWhois ();
?>

The http://www.bkjia.com/PHPjc/317052.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/317052.htmlTechArticle code is as follows :? ClassSearchDomain {var $ domain = ""; functionSetDomain ($ udomain) {$ this-domain = $ udomain ;} //// obtain whois and analyze the domain name status // OK is not registered // non-empty...

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.