Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to check if subdomain exists using php?

Discussion in 'cPanel Developers' started by shido, May 8, 2018.

  1. shido

    shido Registered

    Joined:
    Oct 8, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    51
    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 ?

    Code:
    $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 "<p>Your sub domain name</p>
    <p id='domready'>".$domain."</p>
    
    <p>is available!!</p> }

    Any help would be great!
     
  2. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,628
    Likes Received:
    72
    Trophy Points:
    328
    cPanel Access Level:
    Root Administrator
    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
     
  3. cPanelLauren

    cPanelLauren Forums Analyst
    Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    966
    Likes Received:
    67
    Trophy Points:
    103
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
Loading...

Share This Page