Check If Domain is Subdomain in PHP

3:51 AM

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 ...

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.’;
}

No comments: