bookmark_border​How to check DNS records using PHP

PHP is a very useful programming language, and you can use it, instead of the built-in commands like the Dig command, for querying DNS records. Do you want to know how to check DNS records using PHP? It is a simple process, and there are different PHP functions that you can use. Let’s see them.

​PHP functions for checking DNS records

There are several functions that can be used for checking DNS records. For example, some can check just if the DNS records exist, others serve for only a specific type of DNS record, and others can show any type.

  • checkdnsrr() – This query will see if DNS records exist for the host (hostname or IP address).
  • dns_get_record() – Get the DNS record for the host (hostname or IP address). It could be any type of DNS record.
  • getmxrr() – Get the MX DNS records only, for the host (hostname or IP address).

​checkdnsrr() function 

This will check many different types of DNS resource records. You can specify it with the following parameters: 

  • host – hostname or IP address.
  • type – The particular type of DNS record that you are interested in, like A, AAAA, MX, SOA, NS, CNAME, SRV, TXT, ANY (show all), or another.

The result will be just an answer if there is such a record (“1”) or there is no such a record (“0”). 

Code example:


$all_records_check = checkdnsrr ( ‘’, ‘ANY’ );

echo $all_records_check;


This will check the host for any type of DNS records, and the result is that it does have DNS records (“1”). 


$mx_records_check = checkdnsrr ( ‘’, ‘MX’ );

echo $mx_records_check;


This will check the host for MX DNS records, and the result is that it does have MX records (“1”).

​dns_get_record() function

This PHP function will serve you if you actually need to check the content of the DNS records. It will retrieve the DNS record or records that you asked for from the DNS name server. You have a few parameters that we can use as before:

  • hostname – Here, you can put the hostname like “”. 
  • type – With this parameter, you can specify the type of DNS record that you want to get. Here are some of them that you can use: DNS_A, DNS_AAAA, DNS_CNAME, DNS_HINFO, DNS_SOA, DNS_NS, DNS_PTR, DNS_MX, DNS_TXT, DNS_SRV, DNS_NAPTR, DNS_A6, or DNS_ANY.
  • authns – This will populate the authoritative name server with recource records.
  • addtl – This will populate the authoritative name server with aditional records.
  • raw – Query only the requested type of DNS record, instead of looping type by type before going with the additional information.

This is probably the most used PHP function for checking DNS records because it will return you the actual DNS records. Not like in the previous case, just a confirmation if they exist or not. 

Code example:


$get_any_records = dns_get_record(“”, DNS_A+DNS_NS);



In this case, we are checking for the A records and the NS records.  

​getmxrr() functions

This works only with MX records. This function will get us the MX records for the domain name we are checking. The parameters that can be used with this are below:

  • hostname – The hostname of the target
  • mxhosts – Here, we will see an array of all the available MX records that the query can find. 
  • weight – With this one, it will show the weight information it can find about the order. 

Code example:


$get_mx_records = getmxrr(““, $mx_array);



With this code we will see the MX records for, organized in an array.

Get IPv4 address with PHP explained


PHP serves to get DNS records. It is very easy to use. Try the functions that we mentioned before with the hostname that you need and the particular DNS records. 

bookmark_borderPHP vs. Python: What is the difference?

What is PHP?

PHP, short for Hypertext Preprocessor, is an open-source, server-side scripting and programming language. The primary usage of it is for web development. However, PHP is a very important language for everybody involved in some way with WordPress. The reason for that is because PHP is used for the majority of the core WordPress software. Many people think that PHP as a programming language is not in use anymore, but actually, that is not quite true.

PHP has different versions, which you can benefit from by installing them on your server. The brand new PHP 7.4 and PHP 8.0 come with a lot of new performance improvements rather than the older versions.

It is essential to choose the most recent versions of PHP not only for performance improvements but also for better security.

What is Python?

Python is a common general-purpose programming language. It is also very well known, and it is possible to be applied for a great range of types of applications. In addition, Python offers for its users dynamic typing, high-level data structures, and a lot of other features. All of these benefits are the reason why Python is used for complex application development, being for scripting or, in other cases, for connecting components together, performing like “glue code.” 

In some cases, it can be extended and put in use for performing system calls to nearly any operating system. Also, in addition, to run a code that was written in C or C++.

Thanks to its universality and capability on almost any system architecture, Phyton is a great choice. So that helps for it to be a universal language and to be seen used in all kinds of various applications.

PHP vs. Python

  • PHP is for Hypertext Preprocessor applied to develop a dynamic website or web application. On the other hand, Python is a high-level object-oriented programming language that is applied for accelerated application development.
  • PHP is usually the choice for a language when we are talking about web development. In the other case, Python is commonly applied in data science, AI, and scientific society.
  • PHP holds a number of frameworks, and Python has a pretty small amount of frameworks.
  • When we are analyzing PHP vs. Python for web development, PHP has an extensive variety of syntax and naming conventions. On the other hand, Python appears with a very concise and precise syntax of codes.
  • The key features of PHP are open source, constant improvements, and simple deployment. For Python, the key characteristics are dynamic typing and rapid development.

Which one to choose?

For sure, deciding which one to choose, PHP vs. Python, is an assuredly not so easy job, even after analyzing the differences between them. The reason is that both of them, PHP vs. Python are great options in their own specific way. Like we mentioned, PHP is applied for web development and server-side scripting. In the other case, Python is the gateway to machine learning codes.