Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2003
    Posts
    84

    how to create dynamic subdomains using php

    this is what I need to do.

    when user registered, php script dynamic creates subdomain for user.


    username : abc.

    instead showing www.123.com/abc

    it shows , abc.123.com

    if possible , please give me working code I can study.

    searching on google for month, still have no idea.

  2. #2
    I do not know how to do it exactly, but I know it can be done with mod rewrite in a .htaccess file.

  3. #3
    Join Date
    Sep 2005
    Posts
    550
    Well, to do the subdomain part, you would have to set an "a" record for *.yourdomain.com to go to yourdomain.com. Then on your index.php, you would need to check the accessed url and display information as it pertains to the "abc" part of the url. Hope you understand this.

  4. #4
    Join Date
    Jan 2006
    Location
    Sydney, Australia
    Posts
    251
    You can check $_SERVER['SERVER_NAME'] in PHP for the host name which this script is invoked.

    For example in your HTTP configuration you can have all sub domains pointing to the same PHP files, and then you can have something like

    Code:
    // $hostname will be "abc.123.com"
    $hostname = $_SERVER['SERVER_NAME'];
    // $subdomain will be "abc"
    $subdomain = substr($hostname, 0, strpos($hostname, '.'));

  5. #5
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,342
    Are you using any control panel?

    Peace,
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  6. #6
    Join Date
    Dec 2005
    Posts
    395
    are you using cPanel? If so I have a script you could use

  7. #7
    I could use this as well, and I am on cPanel. Could you share with me DanCF?

  8. #8
    Join Date
    Dec 2005
    Posts
    395
    Just for the record I did not write this

    PHP Code:
    ###############################################################
    # cPanel Subdomains Creator 1.0
    ###############################################################
    #Defining cPanel login info
    $cpaneluser="xxxxxxxx";
    $cpanelpass="xxxxxxxx";
    ###############################################################
    #Sets subdomain to create
    $domain "maindomain.com";
    $subd 'subdomain.maindomain.com';
    ###############################################################
    #Tells where to go
    $request "/frontend/x/subdomain/doadddomain.html?rootdomain=$domain&domain=$subd";
    #$request ="/frontend/x/subdomain/dodeldomain.html?domain=$user_$domain";
    ###############################################################
    #open socket
    $sock fsockopen('ssl://localhost',2083);
    ###############################################################
     
     
    $authstr "$cpaneluser:$cpanelpass";
      
    $pass base64_encode($authstr);
      
    $in "GET $request\r\n";
      
    $in .= "HTTP/1.0\r\n";
      
    $in .= "Host:localhost\r\n";
      
    $in .= "Authorization: Basic $pass\r\n";
      
    $in .= "\r\n";

    fputs($sock$in);
      while (!
    feof($sock)) {
        
    $result .= fgets ($sock,128);
      }

    fclose$sock );


    This script requires openSSL to be compiled with apache

  9. #9
    Join Date
    Dec 2005
    Posts
    395
    lol .



    I meant I didn't initially write the code. I found it somewhere using google.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •