How to check if subdomain exists using php?
I am trying to check if a subdomain already exists using php. I am trying to read the etc/localdomains file using php but it says the file dosnt exist ?
Any help would be great!
$domain = "mysub.mydomain.com";
$filename = '/etc/localdomains';
if( strpos(file_get_contents('/etc/localdomains'),$domain) !== false) {
echo "Subdomain already taken.. Please choose another";
} else {
echo "Your sub domain name
".$domain."
is available!!
}Any help would be great!
-
There are some syntax errors in your script - you need to add a "; before the closing } bracket in the else statement. Are you sure that mysub.mydomain.com exists in /etc/localdomains? cat /etc/localdomains | grep mysub.mydomain.com Of course, this is also going to match if notmysub.mydomain.com exists in /etc/localdomains 0 -
While I can't give you PHP development advice specifically - The addsubdomain cPAPI2 function will provide an error in the event a subdomain exists already and allow creation if it doesn't which may be helpful: cPanel API 2 Functions - SubDomain::addsubdomain - Developer Documentation - cPanel Documentation 0
Please sign in to leave a comment.
Comments
2 comments