× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Get WHOIS data with PHP by querying WHOIS servers.

<p>This is a shortened version of my blog post which you can find on my website here: <a href="https://helgesverre.com/blog/how-to-query-whois-servers-with-php/">How to query WHOIS servers in PHP</a></p> <p>If you are working on an app or a simple site that needs to grab information from the WHOIS server for a domain, such as the domain expiration date, domain owner or various other information, this can be very useful for you to know.</p> <p>The way you query a WHOIS server is very simply, all you have to do is to establish a connection to the server on <strong>Port 43</strong> and send the domain name you want to get data for followed by a <span style="background-color:rgb(255, 255, 255)">Carriage Return and Line Feed, which in PHP is essentially this string: <strong>"\r\n"</strong></span></p> <p>The WHOIS protocol is described in more detail in the <a href="http://tools.ietf.org/html/rfc3912">RFC 3912</a></p> <p> </p> <pre>&lt;?php $whois = []; // Open a Socket connection to our WHOIS server $whoisSocket = fsockopen("whois.verisign-grs.com", 43); // The data we're sending $out = "helgesverre.com\r\n"; // Send the data fwrite($whoisSocket, $out); // grab the next 128 bytes until there ar eno more bytes to grab while (!feof($fp)) { $whois[] = fgets($$whoisSocket, 128); } echo "&lt;pre&gt;"; echo implode("\n", $whois);</pre> <p> </p> <p>The first parameter of the fsockopen function is the WHOIS server for the domain extension you are querying data for, a full list of these can be found on the <a href="http://www.iana.org/domains/root/db">IANA website</a>.</p>
comments powered by Disqus