Looking to Build/Redesign a Website or Blog ?

To speak to Rakshit, call +91 968 704 2303

Check If Domain is Subdomain in PHP

Hello Friends,

If you are looking to get a code for checking Domain is subdomain or not in PHP than you are at right place and you will get working code as always. Using PHP, you can check if your domain is subdomain or not. You just need to call below function and pass subdomain url and you will get a true or false in return depending on result.

Below is the function which split domain name and check for if domain is subdomain or not. If your main domain contains two words like .co.uk or .com.au etc etc than change the number “2” to “3” in if condition.

function check_subdomain($subdomain) {
$subdomainarr = explode(‘.’, $subdomain);
if(count($subdomainarr) > 2) {
return true;
} else {
return false;

$current_domain = $_SERVER[‘HTTP_HOST’];
if(check_subdomain($current_domain)) {
echo ‘Yes, This is Subdoamin.’;
} else {
echo ‘Sorry, this is not a subdomain.’;

Check If Domain is Subdomain in PHP, Check Subdomain in PHP, Validate Subdomain in PHP, Checking whether Domain is subdomain, Subdomain Validation in PHP, Create Subdomain Dynamically, Delete Subdomain Dynamically



  • I am already working with .NET framework. But I also want to learn PHP. So, I hope to starting soon with the same and your website will definitely going to help me.
    Thanks for the post.

  • Hi there just wanted to give you a brief heads up and
    let you know a few of the images aren’t loading correctly. I’m not sure why but I think its a linking
    issue. I’ve tried it in two different browsers and both show the same outcome.

Leave a Reply

Your email address will not be published.